nx-labs icon indicating copy to clipboard operation
nx-labs copied to clipboard

rspack does not properly resolve tsconfig paths.

Open RoyalHunt opened this issue 1 year ago • 7 comments

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

  1. Generate app: npx nx generate @nx/rspack:application --name=app
  2. add path to the tsconfig with /*
  3. 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

RoyalHunt avatar May 14 '24 12:05 RoyalHunt

I'm having the same issue as you.

ghost avatar Jun 22 '24 13:06 ghost

same

rafakwolf avatar Jul 02 '24 16:07 rafakwolf

Also having this issue

tomdglenn91 avatar Jul 03 '24 17:07 tomdglenn91

I'm struggling with this....

luisnquin avatar Aug 22 '24 18:08 luisnquin

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.

artgoce avatar Sep 11 '24 21:09 artgoce

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;
  },
);

jesperume avatar Sep 19 '24 13:09 jesperume

it works for me

"paths": {
      "@/*": ["apps/core/src/modules/*"], // for vscode
      "@": ["apps/core/src/modules"], // for rspack
}

KhBaterdene avatar Nov 13 '24 10:11 KhBaterdene

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");

sudo-vaibhav avatar Sep 10 '25 17:09 sudo-vaibhav