fix(@stdlib/string/base/atob): guard against undefined atob global#13557
Closed
Planeshifter wants to merge 2 commits into
Closed
fix(@stdlib/string/base/atob): guard against undefined atob global#13557Planeshifter wants to merge 2 commits into
atob global#13557Planeshifter wants to merge 2 commits into
Conversation
The job `Node.js v12` and `Node.js v14` on workflow `linux_test` failed on develop with `ReferenceError: atob is not defined` when requiring `@stdlib/string/base/atob`. Root cause: `lib/global.js` referenced the bare `atob` identifier at module-evaluation time; Node.js versions below v16 do not expose `atob` as a global, so `require()` throws before `lib/index.js` ever gets a chance to route to the polyfill via `@stdlib/assert/has-atob-support`. This commit guards the reference with `typeof atob === 'function'`, mirroring the established pattern used by `@stdlib/assert/has-atob-support/lib/atob.js` and `@stdlib/utils/global/lib/global.js`, so that requiring the module no longer throws on environments lacking a native `atob`. Ref: https://github.com/stdlib-js/stdlib/actions/runs/29681875444
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
…rule The `Lint Changed Files` check on PR #13557 failed on `global.js` with `n/no-unsupported-features/node-builtins`: the `eslint-plugin-n` rule flags the guarded `atob` reference because the package's configured minimum supported Node.js version is below v16.0.0, when `atob` first became a global. The reference is intentionally guarded via `typeof` for exactly this reason, matching the same pattern already used elsewhere in the codebase for other version-gated builtins, e.g. `@stdlib/os/homedir/lib/index.js`. This commit adds the matching `eslint-disable-line` comment so the lint check passes without changing runtime behavior. Ref: https://github.com/stdlib-js/stdlib/actions/runs/29690512042
Member
|
Isn't this a duplicate PR? |
Member
Author
|
Yes — this duplicates #13329, opened 2026-07-06 for the same root cause, still open and passing CI. I missed the open-PR check before starting this one. Closing in favor of #13329. Generated by Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request:
ReferenceError: atob is not definedcrash on Node.js v12/v14 in@stdlib/string/base/atobby guarding the module-scope reference to theatobglobal.Related Issues
This pull request has the following related issues:
Questions
No.
Other
Failing run
linux_test#29681875444, jobs "Node.js v12" and "Node.js v14", branchdevelop.Symptom
Root cause
global.jsdidmodule.exports = atob;— a bare reference evaluated at require time. Node <16 doesn't defineatobglobally.index.jsrequiresmain.js(which requiresglobal.js) unconditionally, before@stdlib/assert/has-atob-supportever runs, so the crash preempts the environment-detection logic meant to handle exactly this case.Fix
global.jsnow reads:typeofon an undeclared identifier never throws. On Node 16+/browsers, behavior is unchanged — the native function is exported as before.hasAtobSupport()still gates the polyfill path inindex.js;main.js's try/catch is untouched.Validation
vmsandbox with no globalatob:global.jsno longer throws, exportsnull.atobNode:atob('SGVsbG8sIHdvcmxk')→'Hello, world'throughglobal.js→main.js→index.js.npm test/make lint-pkgnot runnable in this sandbox (nonode_modules;npm installblocked by registry min-release-age policy ones-object-atoms@^1.1.2).node --checkconfirms valid syntax.Reviewer notes
Non-blocking: fix is platform-agnostic and should also cover this failure class on other Node <16 matrix jobs (
windows_test_npm_install,macos_test_npm_install), not justlinux_test.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was written primarily by Claude Code, running an automated CI-failure investigation and fix routine: it identified the failing run, diagnosed the root cause, authored the fix, and drafted this description, all based on the linked CI failure log.
@stdlib-js/reviewers
Generated by Claude Code