nx-labs
nx-labs copied to clipboard
rspack does not properly resolve tsconfig paths.
Current Behavior
tsconfig.json file:
{ "compilerOptions": { "paths": { "@app/themes/*": ["libs/themes/src/muiThemes/*"] } }, }
it resolves in rspack config as:
resolve: { alias: { '@app/themes/*': 'C:\\Users\\admin\\webApps\\libs\\themes\\src\\muiThemes\\*', }, },
Expected Behavior
tsconfig.json file:
{ "compilerOptions": { "paths": { "@app/themes/*": ["libs/themes/src/muiThemes/*"] } }, }
it should resolve in rspack config as:
{ resolve: { alias: { '@app/themes': 'C:\\Users\\admin\\webApps\\libs\\themes\\src\\muiThemes', }, }, }
GitHub Repo
No response
Steps to Reproduce
- Generate app: npx nx generate @nx/rspack:application --name=app
- add path to the tsconfig with /*
- check rspack config
Nx Report
Node : 20.12.2
OS : win32-x64
npm : 10.5.0
nx : 18.3.3
@nx/js : 18.3.3
@nx/jest : 18.3.3
@nx/linter : 18.3.3
@nx/eslint : 18.3.3
@nx/workspace : 18.3.3
@nx/cypress : 18.3.3
@nx/devkit : 18.3.3
@nx/eslint-plugin : 18.3.3
@nx/react : 18.3.3
@nx/storybook : 18.3.3
@nx/web : 18.3.3
@nx/webpack : 18.3.3
@nx/rspack : 18.3.3
typescript : 5.4.5
Failure Logs
No response
Package Manager Version
10.5.0
Operating System
- [ ] macOS
- [ ] Linux
- [X] Windows
- [ ] Other (Please specify)
Additional Information
No response
I'm having the same issue as you.
same
Also having this issue
I'm struggling with this....
My "workaround" was to update rspack config to use this:
https://rspack.dev/config/resolve#resolvetsconfigconfigfile
So, you point to you app/lib tsconfig file.
I solved it with this workaround in rspack.config.ts:
export default composePlugins(
withNx(),
withReact(),
withModuleFederation(config, { dts: false }),
(config: any) => {
// Fix to set correct configuration for alias
const newAlias: Record<string, string> = {};
for (const key in config.resolve.alias) {
const newKey = key.replace(/\/\*/g, "");
const newValue = config.resolve.alias[key].replace(/\\\*/g, "");
newAlias[newKey] = newValue;
}
config.resolve.alias = newAlias;
return config;
},
);
it works for me
"paths": {
"@/*": ["apps/core/src/modules/*"], // for vscode
"@": ["apps/core/src/modules"], // for rspack
}
My "workaround" was to update rspack config to use this:
https://rspack.dev/config/resolve#resolvetsconfigconfigfile
So, you point to you app/lib tsconfig file.
for people on nx, you probably would be fine with passing base tsconfig, instead of the tsconfig of the app using rspack
config.resolve.tsConfig = path.resolve(__dirname, "../../tsconfig.base.json");