rspack
rspack copied to clipboard
Module resolving not works as same as webpack does while module path starts with a slash ('/')
System Info
System: OS: macOS 13.4 CPU: (8) arm64 Apple M1 Memory: 62.98 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 18.16.0 - /usr/local/bin/node Yarn: 1.22.11 - ~/.npm-global/bin/yarn npm: 9.5.1 - /usr/local/bin/npm pnpm: 8.6.0 - ~/Library/pnpm/pnpm Watchman: 2023.05.22.00 - /opt/homebrew/bin/watchman Browsers: Chrome: 114.0.5735.133 Safari: 16.5 npmPackages: @rspack/cli: ^0.2.4 => 0.2.4
Details
import "/src/deps.tsx";
got an error:
error[internal]: Failed to resolve /src/deps.tsx in typescriptx|/.../rspack-test/module-path-starts-with-slash-error/src/index.tsx
That's make sense when importing an js module 'casue it's seems like an absolute path.
But css-loader will transpile ~/ to /, it works will in webpack but not working in rspack.
@import `~/some/path/test.css`;
Reproduce link
https://github.com/PIMBA/rspack-tests/tree/main/module-path-starts-with-slash-error
Reproduce Steps
- pnpm i
- pnpm run dev
- pnpm run webpack-dev
working with css-loader case see here
- pnpm i
- pnpm run dev
- pnpm run webpack-dev
can you try webpack with set experiments.css:true, I think this is the same behavior with webpack
good to notice that the current rspack's css implementation align with webpack native css (not with css-loader, but you can still use css-loader in rspack)
can you try webpack with set experiments.css:true, I think this is the same behavior with webpack
just had time to test experiments.css:true...
I think it's still some differences between rspack and webpack module resolution.
@import '/style/some-file.css';
works well on webpack with experiments.css:true:
but got an error on rspack:
@PIMBA https://github.com/webpack/webpack/blob/main/lib/config/defaults.js#L1446 it's because webpack set resolve.roots = [context] as default vaue, but rspack doesn't support roots yet
This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!
bump
@Boshen another user met this issue, can you take a look
Waiting for responses on https://github.com/web-infra-dev/rspack/pull/5572
I cloned the repo and tested the latest Rspack version, it throws the resolution error
ERROR in × Resolve error: Can't resolve '/Users/bytedance/github/rspack-tests/module-path-starts-with-slash-error/node_modules/.pnpm/@[email protected]/node_modules/@rspack/core/hot/dev-server.js' in '/
│ Users/bytedance/github/rspack-tests/module-path-starts-with-slash-error'
ERROR in × Resolve error: Can't resolve '/Users/bytedance/github/rspack-tests/module-path-starts-with-slash-error/node_modules/.pnpm/
│ @[email protected]_@[email protected][email protected][email protected]/node_modules/@rspack/dev-server/client/index.js?
│ protocol=ws%3A&hostname=0.0.0.0&port=8080&pathname=%2Fws&logging=info&overlay=%7B%22errors%22%3Atrue%2C%22warnings%22%3Afalse%7D&reconnect=10&hot=true&live-reload=true' in '/Users/bytedance/
│ github/rspack-tests/module-path-starts-with-slash-error'
if I add
resolve: {
roots: ["/path/to/rspack-tests/module-path-starts-with-slash-error"]
}
but oxc-resolver passes if I test it alone with roots.
I am doing Migration from webpack. File - src/components/NewCard import commonStyle from "/src/components/CommonStyle.module.css";
Resolve error: Can't resolve '/src/components/CommonStyle.module.css' in '/Users/sbc/new-app/src/components/NewCard'
This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!
@PIMBA this is fixed in alpha version 1.0.0-alpha.3, please try
