[Bug]: `resolve.dedupe` should support exports fields
Version
@rsbuild/core 1.3.21
Details
"The alias expanded to an absolute path does not respect exports field."
- config like this
// rsbuild.config.ts
resolve: {
dedupe: ['@tt/web']
}
Add the following two aliases to rspack:
// rspack.config.ts(Rsbuild actually generated)
resolve: {
alias: {
"@tt/web$": '/usr/demos/rsbuild/node_modules/.pnpm/@[email protected]/@tt/web',
"@tt/web/*": '/usr/demos/rsbuild/node_modules/.pnpm/@[email protected]/node_modules/@tt/web'
}
}
If the user writes as below
import foo from "@tt/web/canary"
it is actually equal to
import foo from "/usr/demos/rsbuild/node_modules/.pnpm/@[email protected]/node_modules/@tt/web/canary"
At this moment, if the exports of @tt/web are written like this:
// @tt/web/package.json
exports: {
"./canary": "./dist/canary.js"
}
Error: resolve not found
Reproduce link
none
Reproduce Steps
none
My idea is to modify it to this API, which can solve this problem and make it more user-friendly.
resolve: {
alias: {
"@tt/web/(.*)": {
base: "/usr/demos/rsbuild/node_modules/.pnpm/@[email protected]/node_modules/@tt/web",
request: "@tt/web/$1"
}
}
}
Related: https://github.com/jkrems/proposal-pkg-exports/#:~:text=The%20exports%20target%20must%20be%20a%20string%20and%20start%20with%20%22./%22%20(URLs%20and%20absolute%20paths%20are%20not%20currently%20supported%20but%20may%20be%20supported%20in%20future).
It seems that there is no perfect solution to this problem, so is there an option to provide a more open configuration. Let users customize subpath configuration.
For example, ‘@tt/web/xxx’, through require.resolve, you actually get the real address and support the exports field. So it may be necessary to modify the internal dedupe solution to get alias path. Of course, this seems to have some problems.
@chenjiahan @SoonIter cc
Any progress on this?
If the resolver cannot resolve wildcard correctly for now, can we iterate over exports in Rsbuild and set alias using manually resolve (with correct conditionName)?
No progress yet.. @stormslowly cc