aidenybai / aidenybai/react-scan

react-scan 0.5.6+ fails on Rspack: named export from react-grab/package.json

Aperta
#467 3 commenti 1 reazione 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
21.8k
Fork
390
Merge medio
23m
PR unite (30g)
1

Descrizione

## Description

`react-scan@0.5.7` fails to build with Rsbuild/Rspack because its published ESM bundle uses a named import from a JSON module:

```js
import { version as REACT_GRAB_VERSION } from "react-grab/package.json";
```

Rspack treats `react-grab/package.json` as a default-exporting JSON module, so the named `version` export cannot be linked.

## Reproduction

```tsx
import { scan } from "react-scan";

scan({
enabled: true,
});
```

Then run an Rsbuild production build.

### Environment A

- react-scan: 0.5.7
- react-grab: 0.1.37
- @rsbuild/core: 2.0.5
- @rspack/core: 2.0.2
- React: 18.3.1
- Node.js: 20.19.6
- pnpm: 10.12.1

### Environment B

I also reproduced after upgrading the complete bundler pair:

- react-scan: 0.5.7
- @rsbuild/core: 2.1.7
- @rspack/core: 2.1.5
- React: 18.3.1
- Node.js: 20.19.6
- pnpm: 10.12.1

## Actual behavior

```text
ESModulesLinkingError: Can't import the named export 'version'
(imported as 'REACT_GRAB_VERSION') from default-exporting module
(only default export is available)

File: react-scan/dist/index.mjs
```

Import trace:

```text
src/index.tsx
src/bootstrap.tsx
src/App.tsx
react-scan/dist/index.mjs
```

## Expected behavior

Importing `scan` from `react-scan` should build successfully with current Rsbuild/Rspack.

## Regression range

- `react-scan@0.5.5`: builds successfully
- `react-scan@0.5.6`: published bundle contains the problematic JSON named import
- `react-scan@0.5.7`: same failure

Upgrading Rspack from 2.0.2 to 2.1.5 does not resolve the error.

## Suggested fix

Avoid emitting a named JSON import in the published ESM bundle. For example, use a default JSON import and read `.version`, or preferably inject the react-grab version as a string during the react-scan build so consumers do not need to bundle `react-grab/package.json`.

Thank you.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.