Skip to content

fix(@stdlib/string/base/atob): guard against missing global atob#13286

Draft
Planeshifter wants to merge 2 commits into
developfrom
philipp/ci-fix-atob-node-legacy-2026-07-05
Draft

fix(@stdlib/string/base/atob): guard against missing global atob#13286
Planeshifter wants to merge 2 commits into
developfrom
philipp/ci-fix-atob-node-legacy-2026-07-05

Conversation

@Planeshifter

Copy link
Copy Markdown
Member

Description

This pull request:

  • fixes a ReferenceError: atob is not defined in @stdlib/string/base/atob on Node.js versions lacking the global atob (<16). lib/global.js bare-referenced atob, which throws at module-load time. Since lib/index.js requires ./main.js (and transitively ./global.js) unconditionally before running its hasAtobSupport() feature detection, this crashed require('@stdlib/string/base/atob') outright on Node.js <16, not just in tests.
  • guards the reference with typeof atob === 'function', which does not throw on an undeclared identifier, matching the existing pattern in @stdlib/assert/has-atob-support/lib/atob.js. On unsupported platforms, the module now resolves to null, and the existing try/catch in main.js plus the hasAtobSupport() check in index.js handle the rest as originally intended.

Related Issues

None.

Questions

No.

Other

Failing run: https://github.com/stdlib-js/stdlib/actions/runs/28736797063 (linux_test, jobs "Node.js v12" and "Node.js v14")

Symptom: ReferenceError: atob is not defined at lib/node_modules/@stdlib/string/base/atob/lib/global.js:23:18, thrown from test/test.main.js on require, before tape's skip option ever takes effect.

Root cause: bare (unguarded) reference to the global atob in global.js, executed unconditionally at module load via index.jsmain.jsglobal.js, regardless of the package's own hasAtobSupport() feature detection.

Validation: confirmed via manual node -e runs that (1) requiring lib/main.js with globalThis.atob deleted no longer throws and now returns null on invocation, (2) requiring lib/index.js in the same simulated environment correctly falls back to the polyfill and returns the correct decoded string, (3) normal behavior on a Node.js version with native atob is unchanged. A full node_modules install was not available in this environment to run the package's tape suite directly. Reviewed independently by three agents (correctness, regression scope, style/conventions) — all approved, no blocking findings.

Checklist

AI Assistance

  • Yes

  • No

  • Code generation (e.g., when writing an implementation or fixing a bug)

  • Test/benchmark generation

  • Documentation (including examples)

  • Research and understanding

Disclosure

This PR was authored by Claude Code as part of an automated CI-failure investigation routine: it identified the failing nightly job, root-caused the ReferenceError, applied the fix, and validated it against three independent review passes before opening this draft.


@stdlib-js/reviewers


Generated by Claude Code

The job `linux_test (Node.js v12)` and `linux_test (Node.js v14)` on
workflow `linux_test` failed on develop with `ReferenceError: atob is
not defined` at `lib/global.js:23`. Root cause: the module bare-
referenced the global `atob` at load time, which throws on any Node.js
version lacking that global (added in Node.js 16). Since `lib/index.js`
requires `./main.js` (and transitively `./global.js`) unconditionally
before its `hasAtobSupport()` feature-detection runs, this crashed on
`require()` in production on Node.js <16, not just in tests.

This commit guards the reference with `typeof atob === 'function'`,
which does not throw on an undeclared identifier, matching the existing
pattern in `@stdlib/assert/has-atob-support/lib/atob.js`. The module now
safely resolves to `null` on unsupported platforms, letting the
try/catch in `main.js` and the `hasAtobSupport()` check in `index.js`
work as intended.

Ref: https://github.com/stdlib-js/stdlib/actions/runs/28736797063
@stdlib-bot

stdlib-bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
string/base/atob $\\color{green}217/217$
$\\color{green}+100.00\\%$
$\\color{red}11/12$
$\\color{green}+91.67\\%$
$\\color{green}2/2$
$\\color{green}+100.00\\%$
$\\color{green}217/217$
$\\color{green}+100.00\\%$

The above coverage report was generated for the changes in this PR.

…arded `atob` reference

CI check `Lint Changed Files` failed on this PR with two
`n/no-unsupported-features/node-builtins` errors on the `typeof atob`
guard added in the previous commit: the repo's configured Node.js
version floor (>=0.12.18) predates the `atob` global (added in Node.js
16), and eslint-plugin-n flags the reference regardless of the
`typeof` guard protecting it at runtime.

This adds the same `eslint-disable-line` used for identical
version-gated feature-detection elsewhere in the codebase, e.g.
`@stdlib/os/homedir/lib/index.js` and
`@stdlib/process/geteuid/lib/native.js`.

Ref: https://github.com/stdlib-js/stdlib/actions/runs/28743835208
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants