rspack icon indicating copy to clipboard operation
rspack copied to clipboard

Module resolving not works as same as webpack does while module path starts with a slash ('/')

Open PIMBA opened this issue 2 years ago • 9 comments

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

  1. pnpm i
  2. pnpm run dev
  3. pnpm run webpack-dev

working with css-loader case see here

  1. pnpm i
  2. pnpm run dev
  3. pnpm run webpack-dev

PIMBA avatar Jun 28 '23 08:06 PIMBA

can you try webpack with set experiments.css:true, I think this is the same behavior with webpack image

hardfist avatar Jun 29 '23 04:06 hardfist

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)

hardfist avatar Jun 29 '23 04:06 hardfist

can you try webpack with set experiments.css:true, I think this is the same behavior with webpack image

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: image but got an error on rspack: image

PIMBA avatar Jun 30 '23 01:06 PIMBA

@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

hardfist avatar Aug 10 '23 11:08 hardfist

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!

stale[bot] avatar Dec 15 '23 15:12 stale[bot]

bump

PIMBA avatar Dec 22 '23 07:12 PIMBA

@Boshen another user met this issue, can you take a look

hardfist avatar Dec 28 '23 11:12 hardfist

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.

Boshen avatar Feb 05 '24 09:02 Boshen

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'

arjunsoundankar avatar Mar 18 '24 09:03 arjunsoundankar

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!

stale[bot] avatar Jul 10 '24 04:07 stale[bot]

@PIMBA this is fixed in alpha version 1.0.0-alpha.3, please try

hardfist avatar Jul 12 '24 02:07 hardfist