Skip to content

fix: error unexpected token in fetch JS compatibility issue with Webpack 4#10864

Merged
jasonsaayman merged 5 commits into
v1.xfrom
10851-build-error-unexpected-token-in-libadaptersfetchjs-compatibility-issue-with-webpack-4-vue-27
May 7, 2026
Merged

fix: error unexpected token in fetch JS compatibility issue with Webpack 4#10864
jasonsaayman merged 5 commits into
v1.xfrom
10851-build-error-unexpected-token-in-libadaptersfetchjs-compatibility-issue-with-webpack-4-vue-27

Conversation

@jasonsaayman
Copy link
Copy Markdown
Member

@jasonsaayman jasonsaayman commented May 7, 2026

Summary

Restore Webpack 4 / ES2018 compatibility for lib/adapters/fetch.js. The fetch adapter was using the nullish coalescing operator (??), which is ES2020 syntax and breaks consumers bundling axios source with Webpack 4 (e.g. Vue 2.7 projects). axios's lib/ source has always been intended to stay ES2018-compatible; the lint config already enforces ecmaVersion: 2018, but the rule was never wired into CI, so the regression slipped through.

Linked issue

Closes #10851

Changes

  • lib/adapters/fetch.js: replace utils.global ?? globalThis with an explicit !== undefined && !== null ternary so the source parses under ES2018.
  • .github/workflows/run-ci.yml: run npm run lint in the build-and-run-vitest job, so the existing ecmaVersion: 2018 rule is actually enforced on PRs.
  • tests/unit/syntaxCompat.test.js: new vitest unit test that parses every lib/**/*.js file with acorn at ecmaVersion: 2018 defence in depth so any future ES2019+ syntax in lib/ fails a named test, not just a generic lint error.
  • eslint.config.js: add globalThis: 'readonly' to the lib globals blocks (the bare globalThis reference was previously masked by the ?? parse error; once parsing succeeds, no-undef flags it).
  • package.json / package-lock.json: add acorn ^8.16.0 as a devDependency for the new test.

Checklist

  • Tests added or updated (or N/A with reason) — new tests/unit/syntaxCompat.test.js covers the regression class
  • Docs / types updated if public API changed (index.d.ts and index.d.cts) — N/A, no public API change
  • No breaking changes (or called out explicitly above) runtime behaviour preserved; the ternary preserves the original nullish semantics

Summary by cubic

Restores ES2018 compatibility in the fetch adapter to fix “Unexpected token ??” build errors when bundling axios with webpack 4 / vue 2.7. CI now enforces ES2018 syntax and adds a parsing test to prevent regressions. Addresses #10851.

Description

  • Summary of changes

    • Replaced ?? in lib/adapters/fetch.js with an ES2018-safe ternary.
    • Added npm run lint to CI to enforce ecmaVersion: 2018.
    • New test tests/unit/syntaxCompat.test.js parses all lib/**/*.js with acorn at ES2018.
    • Declared globalThis: 'readonly' in eslint.config.js for lib targets.
    • Added acorn as a devDependency.
  • Reasoning

    • lib/ is intended to stay ES2018. ?? is ES2020 and breaks webpack 4 builds.
    • Lint and parsing tests catch future syntax regressions early.
  • Additional context

Docs

  • Add a note in /docs/ about lib/ targeting ES2018.
  • Mention compatibility with webpack 4 and vue 2.7 when bundling axios source.

Testing

  • Added tests/unit/syntaxCompat.test.js (acorn ES2018 parse over all lib/**/*.js).
  • CI now runs npm run lint.
  • No additional unit tests needed for runtime behavior; existing suites should remain green.

Semantic version impact

  • Patch: internal syntax fix and CI/test hardening. No API changes.

Written for commit ab8ecfb. Summary will update on new commits.

@jasonsaayman jasonsaayman self-assigned this May 7, 2026
@jasonsaayman jasonsaayman added priority::medium A medium priority commit::fix The PR is related to a bugfix labels May 7, 2026
@jasonsaayman jasonsaayman changed the title 10851 build error unexpected token in libadaptersfetchjs compatibility issue with webpack 4 vue 27 fix: error unexpected token in fetch JS compatibility issue with Webpack 4 May 7, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 6 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

@jasonsaayman jasonsaayman merged commit 3e6b4e1 into v1.x May 7, 2026
27 checks passed
@jasonsaayman jasonsaayman deleted the 10851-build-error-unexpected-token-in-libadaptersfetchjs-compatibility-issue-with-webpack-4-vue-27 branch May 7, 2026 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit::fix The PR is related to a bugfix priority::medium A medium priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build Error: Unexpected token '??' in lib/adapters/fetch.js (Compatibility issue with Webpack 4 / Vue 2.7)

1 participant