rspack: Failed to wildcard re-export in some cases
System Info
System: OS: macOS 12.6 CPU: (10) arm64 Apple M1 Pro Memory: 2.49 GB / 32.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.19.1 - ~/Library/Caches/fnm_multishells/19580_1682235494023/bin/node npm: 8.19.3 - ~/Library/Caches/fnm_multishells/19580_1682235494023/bin/npm Browsers: Chrome: 112.0.5615.137 Safari: 15.6.1
Details
We are using wildcard re-export to export all methods from react-router-dom
:
export * from 'react-router-dom';
The react-router-dom
provides a useLocation
method, but the method can not be re-exported and there will be an error like this:
error TypeError: (0 , i.useLocation) is not a function
at m (/home/runner/work/modern.js/modern.js/packages/document/main-doc/doc_build/ssr/bundles/main.js:4:317626)
at eX (/home/runner/work/modern.js/modern.js/packages/document/main-doc/doc_build/ssr/bundles/main.js:1:96905)
at e (/home/runner/work/modern.js/modern.js/packages/document/main-doc/doc_build/ssr/bundles/main.js:1:98477)
If we change the wildcard re-export to named export, then the useLocation
can be re-exported as expected.
export { useLocation } from 'react-router-dom';
Reproduce link
https://github.com/web-infra-dev/modern.js
Reproduce Steps
Reproduce the error
git clone git@github.com:web-infra-dev/modern.js.git
git checkout eac19a65400c88323fa0ace1218f5eaad1322f6b
pnpm i
cd packages/document/main-doc
pnpm build
After build, we can see the (0 , i.useLocation) is not a function
error.
Using named export
If we open packages/cli/doc-core/src/runtime/index.ts
and modify the export line:
- export * from 'react-router-dom';
+ export { useLocation } from 'react-router-dom';
cd packages/cli/doc-core
pnpm build
cd ../../document/main-doc
pnpm build:doc
Then the site can be built successfully.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 16 (10 by maintainers)
I can still reproduce this issue with Rspack 0.2.3, so I will re-open this issue until it is fixed.
The only thing I am sure is that it is not caused by tree shaking: I override the rspack config:
still emit the error
further investigation maybe comes later.