Skip to content

fix: do not inline the package version when bundling - #16422

Merged
SimenB merged 1 commit into
jestjs:mainfrom
SimenB:fix-stale-bundled-version
Sep 1, 2026
Merged

SimenB merged 1 commit into
jestjs:mainfrom
SimenB:fix-stale-bundled-version

Conversation

@SimenB

@SimenB SimenB commented Sep 1, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #16420.

Webpack inlines require('../package.json') into each bundle. A release builds first and lets Lerna bump every package.json afterwards, so the published bundles carry the version from before the bump β€” @jest/core@30.5.1 ships "version":"30.5.0" in its build/index.js, and 30.2.0 ships 30.1.3. jest --version and --debug print that stale value. jest-haste-map and @jest/transform read the same constant into their cache keys, so those are labelled one release behind too.

29.7.0 was unaffected: that build emitted one file per module with a real runtime require. It regressed in #12348, which moved the build to webpack.

Marking the request external restores the runtime require. webpackIgnore is not an option β€” webpack honours it on import() and new URL(), not on CommonJS require; with the magic comment in place the output still reads __webpack_require__(/* webpackIgnore: true */"./package.json") and the JSON is still emitted as a module.

The external path is relative to the bundle rather than to the importing source file, so logDebugMessages.ts asking for ../../package.json from src/lib lands in the same place as version.ts asking for ../package.json. No source changes needed.

Test plan

After yarn build:js, no "version":"30.x.y" literal is left in the jest-core, jest-transform or jest-haste-map bundles, and each contains module.exports = require("../package.json").

Editing packages/jest-core/package.json to 99.9.9 after building, then running node packages/jest-cli/bin/jest.js --version, prints 99.9.9-dev β€” the built output reads the file at run time.

grep -rln 'require("../package.json")' packages/*/build/ matches only the three flat build/index.js files. The external assumes a chunk at build/*.js; the one nested entry in the build, jest-jasmine2's jasmine/jasmineLight.js, does not touch package.json.

Webpack inlined `require('../package.json')` into each bundle. Releases
build first and bump `package.json` afterwards, so the shipped bundles
carried the previous version: `jest --version` printed 30.5.0 on 30.5.1,
and `jest-haste-map`/`@jest/transform` built their cache keys from a
stale version too. `webpackIgnore` does not apply to CommonJS `require`,
so mark the request external instead - the bundle is emitted to
`<packageDir>/build`, one level under the file it needs.

Regressed in jestjs#12348, which moved the build to webpack.
@netlify

netlify Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

βœ… Deploy Preview for jestjs ready!

Name Link
πŸ”¨ Latest commit 0041027
πŸ” Latest deploy log https://app.netlify.com/projects/jestjs/deploys/6a97507c48b5b0000866cfbd
😎 Deploy Preview https://deploy-preview-16422--jestjs.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
πŸ€– Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@SimenB
SimenB requested a lite review from Copilot September 1, 2026 22:24
@github-actions github-actions Bot added the require-changelog If a PR does requires a changelog entry label Sep 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟒 Approval recommended

The change is narrowly scoped to webpack externals handling for package.json and aligns with the stated release/build behavior without introducing API or runtime behavior beyond correcting version resolution.

Pull request overview

This PR fixes a regression introduced by webpack bundling where require('../package.json') gets inlined into package bundles, causing jest --version, --debug, and cache key versioning (e.g. in jest-haste-map and @jest/transform) to report the previous release version after Lerna bumps package.json post-build.

Changes:

  • Updates the webpack build config to treat each package’s package.json as a CommonJS external (restoring a runtime require).
  • Adds a changelog entry documenting the fix across the affected packages.
File summaries
File Description
scripts/buildUtils.mjs Adds a webpack externals handler to keep <packageDir>/package.json runtime-required instead of bundled/inlined.
CHANGELOG.md Documents the fix under ## main for jest-core, jest-haste-map, and jest-transform.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

πŸ’‘ Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@pkg-pr-new

pkg-pr-new Bot commented Sep 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

babel-jest

npm i https://pkg.pr.new/babel-jest@16422

babel-plugin-jest-hoist

npm i https://pkg.pr.new/babel-plugin-jest-hoist@16422

babel-preset-jest

npm i https://pkg.pr.new/babel-preset-jest@16422

create-jest

npm i https://pkg.pr.new/create-jest@16422

@jest/diff-sequences

npm i https://pkg.pr.new/@jest/diff-sequences@16422

expect

npm i https://pkg.pr.new/expect@16422

@jest/expect-utils

npm i https://pkg.pr.new/@jest/expect-utils@16422

jest

npm i https://pkg.pr.new/jest@16422

jest-changed-files

npm i https://pkg.pr.new/jest-changed-files@16422

jest-circus

npm i https://pkg.pr.new/jest-circus@16422

jest-cli

npm i https://pkg.pr.new/jest-cli@16422

jest-config

npm i https://pkg.pr.new/jest-config@16422

@jest/console

npm i https://pkg.pr.new/@jest/console@16422

@jest/core

npm i https://pkg.pr.new/@jest/core@16422

@jest/create-cache-key-function

npm i https://pkg.pr.new/@jest/create-cache-key-function@16422

jest-diff

npm i https://pkg.pr.new/jest-diff@16422

jest-docblock

npm i https://pkg.pr.new/jest-docblock@16422

jest-each

npm i https://pkg.pr.new/jest-each@16422

@jest/environment

npm i https://pkg.pr.new/@jest/environment@16422

jest-environment-jsdom

npm i https://pkg.pr.new/jest-environment-jsdom@16422

@jest/environment-jsdom-abstract

npm i https://pkg.pr.new/@jest/environment-jsdom-abstract@16422

jest-environment-node

npm i https://pkg.pr.new/jest-environment-node@16422

@jest/expect

npm i https://pkg.pr.new/@jest/expect@16422

@jest/fake-timers

npm i https://pkg.pr.new/@jest/fake-timers@16422

@jest/get-type

npm i https://pkg.pr.new/@jest/get-type@16422

@jest/globals

npm i https://pkg.pr.new/@jest/globals@16422

jest-haste-map

npm i https://pkg.pr.new/jest-haste-map@16422

jest-jasmine2

npm i https://pkg.pr.new/jest-jasmine2@16422

jest-leak-detector

npm i https://pkg.pr.new/jest-leak-detector@16422

jest-matcher-utils

npm i https://pkg.pr.new/jest-matcher-utils@16422

jest-message-util

npm i https://pkg.pr.new/jest-message-util@16422

jest-mock

npm i https://pkg.pr.new/jest-mock@16422

@jest/pattern

npm i https://pkg.pr.new/@jest/pattern@16422

jest-phabricator

npm i https://pkg.pr.new/jest-phabricator@16422

jest-regex-util

npm i https://pkg.pr.new/jest-regex-util@16422

@jest/reporters

npm i https://pkg.pr.new/@jest/reporters@16422

jest-resolve

npm i https://pkg.pr.new/jest-resolve@16422

jest-resolve-dependencies

npm i https://pkg.pr.new/jest-resolve-dependencies@16422

jest-runner

npm i https://pkg.pr.new/jest-runner@16422

jest-runtime

npm i https://pkg.pr.new/jest-runtime@16422

@jest/schemas

npm i https://pkg.pr.new/@jest/schemas@16422

jest-snapshot

npm i https://pkg.pr.new/jest-snapshot@16422

@jest/snapshot-utils

npm i https://pkg.pr.new/@jest/snapshot-utils@16422

@jest/source-map

npm i https://pkg.pr.new/@jest/source-map@16422

@jest/test-result

npm i https://pkg.pr.new/@jest/test-result@16422

@jest/test-sequencer

npm i https://pkg.pr.new/@jest/test-sequencer@16422

@jest/transform

npm i https://pkg.pr.new/@jest/transform@16422

@jest/types

npm i https://pkg.pr.new/@jest/types@16422

jest-util

npm i https://pkg.pr.new/jest-util@16422

jest-validate

npm i https://pkg.pr.new/jest-validate@16422

jest-watcher

npm i https://pkg.pr.new/jest-watcher@16422

jest-worker

npm i https://pkg.pr.new/jest-worker@16422

pretty-format

npm i https://pkg.pr.new/pretty-format@16422

commit: 0041027

@SimenB
SimenB merged commit 981920c into jestjs:main Sep 1, 2026
104 of 105 checks passed
@SimenB
SimenB deleted the fix-stale-bundled-version branch September 1, 2026 22:53
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

require-changelog If a PR does requires a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: jest --version reports one version back

2 participants