nrwl / nx-labs

A collection of Nx plugins
MIT License
140 stars 51 forks source link

rspack does not properly resolve tsconfig paths. #398

Open RoyalHunt opened 4 months ago

RoyalHunt commented 4 months ago

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

Additional Information

No response

spartan-luc-le commented 3 months ago

I'm having the same issue as you.

rafakwolf commented 3 months ago

same

tomdglenn91 commented 3 months ago

Also having this issue

luisnquin commented 1 month ago

I'm struggling with this....

artgoce commented 3 weeks ago

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.

jesperume commented 1 week ago

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