fix: use default JSON import for react-grab/package.json version (webpack 5 / Next.js 15) - #448
Open
hoklims wants to merge 1 commit into
Open
fix: use default JSON import for react-grab/package.json version (webpack 5 / Next.js 15)#448hoklims wants to merge 1 commit into
hoklims wants to merge 1 commit into
Conversation
Webpack 5 (and other bundlers using ESM JSON modules in strict mode) reject
`import { version } from "<pkg>/package.json"` with:
Can't import the named export 'version' (imported as 'REACT_GRAB_VERSION')
from default-exporting module (only default export is available)
Next.js 15.5 + React 19 triggers this consistently. Switch to a default
import + property access, which is the shape supported across all bundlers
(Webpack 5, Rollup, esbuild, Vite, swc).
No behavioural change.
|
@hoklims is attempting to deploy a commit to the Million Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
Fixes bundling failures in strict ESM JSON-module environments (notably Webpack 5 / Next.js 15) by changing how react-grab/package.json’s version is imported, avoiding unsupported named JSON exports.
Changes:
- Replace named JSON import (
{ version }) with a default JSON import. - Read
versionvia property access and keep the rest of the version-check logic unchanged.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
brandonyoungdev
approved these changes
Jun 1, 2026
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.
Problem
react-scancurrently fails to bundle in any project using Webpack 5 with strict ESM JSON modules — most visibly Next.js 15.5 + React 19. The dev server returns 500s with:This bites any consumer that:
react-scanfrom a Server-Component-side layout via dynamicimport("react-scan")package.jsonexports field is stricter)It does not fire on Vite/esbuild today, but Webpack's stricter handling is the correct interpretation of the spec — named imports from JSON modules aren't standard, so other bundlers may follow suit.
Root cause
packages/scan/src/web/utils/check-react-grab-version.tsdoes:JSON modules expose
{ default: <object> }under the ESM module spec — there's no namedversionexport. Webpack 5 enforces this strictly; the import becomes a hard error in dev and a silentundefinedafter tree-shake in some prod builds.Fix
Default import + property access, which is the universal shape across bundlers:
Compatible with:
No behavioural change —
REACT_GRAB_VERSIONis the same string at runtime.Verification
Reproduction (Next.js 15.5.18 + React 19 + Webpack):
Before this patch: page returns 500 +
ModuleDependencyErrorin the dev console.After this patch (verified locally by patching
node_modules/react-scan/dist/{index,core/all-environments}.mjswith the same fix): page renders, react-scan loads, the dev toolbar appears.Notes
packages/scan/src/web/utils/check-react-grab-version.ts). The compiled output bundles need a rebuild to propagate (running the repo's build pipeline should pick it up cleanly — no other file changes needed).import { … } from "<pkg>/package.json"case.Happy to iterate if you'd rather encode this differently (e.g. read the version from a
version.tsconstant generated at build time).Note
Low Risk
Low risk: a tiny import-shape change to avoid Webpack 5/strict ESM JSON module bundling errors, with no behavioral change beyond ensuring
REACT_GRAB_VERSIONis defined.Overview
Fixes Webpack 5/Next.js strict ESM JSON compatibility by switching
react-grab/package.jsonversion access from a named import to a default JSON import +.version(check-react-grab-version.ts).This prevents bundling/runtime failures where JSON modules only expose a default export, while keeping the existing version-check behavior unchanged.
Reviewed by Cursor Bugbot for commit fba10c2. Bugbot is set up for automated code reviews on this repo. Configure here.