aidenybai / aidenybai/react-scan

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

Abierto
#467 3 comentarios 1 reacción 0 asignados Ver en GitHub
Lenguaje dominante
TypeScript
Estrellas
21.8k
Forks
390
Merge medio
23 min
PR fusionados (30 d)
1

Descripción

## 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.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.