nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.78k stars 2.37k forks source link

Nx tsconfig paths alias resolution is not working as expected #28945

Open Diboby opened 1 week ago

Diboby commented 1 week ago

Current Behavior

Hello !

The @nx/vite/plugins/nx-tsconfig-paths.plugin path resolution is not working as expected.

I think the first tsconfig is supposed to be the project tsconfig (https://github.com/nrwl/nx/blob/master/packages/vite/plugins/nx-tsconfig-paths.plugin.ts#L117) but in my case, it resolves to the tsconfig under the workspace root foder.

Image

Expected Behavior

I think the first tsconfig is supposed to be the project tsconfig (https://github.com/nrwl/nx/blob/master/packages/vite/plugins/nx-tsconfig-paths.plugin.ts#L117) but in my case, it resolves to the tsconfig under the workspace root foder.

GitHub Repo

https://github.com/nrwl/nx/blob/master/packages/vite/plugins/nx-tsconfig-paths.plugin.ts#L117

Steps to Reproduce

  1. root tsconfig
{
  "compileOnSave": false,
  "compilerOptions": {
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "module": "esnext",
    "lib": ["es2020", "dom"],
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "baseUrl": ".",
    "paths": {}
  },
  "exclude": ["node_modules", "tmp"]
}
  1. project tsconfig
{
  "compilerOptions": {
    "jsx": "react-jsx",
    "allowJs": true,
    "esModuleInterop": false,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "types": ["vite/client", "vitest"],
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "files": [],
  "include": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.spec.json"
    }
  ],
  "extends": "../../tsconfig.base.json"
}

Nx Report

Node           : 20.17.0
OS             : darwin-x64
Native Target  : x86_64-macos
npm            : 10.8.2

nx                 : 20.0.3
@nx/js             : 20.0.3
@nx/jest           : 20.0.3
@nx/eslint         : 20.0.3
@nx/workspace      : 20.0.3
@nx/cypress        : 20.0.3
@nx/devkit         : 20.0.3
@nx/eslint-plugin  : 20.0.6
@nx/react          : 20.0.3
@nx/vite           : 20.0.3
@nx/web            : 20.0.3
typescript         : 5.6.3
---------------------------------------
Registered Plugins:
@nx/vite/plugin
@nx/eslint/plugin
@nx/cypress/plugin
@nx/jest/plugin
---------------------------------------

Failure Logs

[Nx Vite TsPaths] Resolved @/contexts to undefined

Package Manager Version

No response

Operating System

Additional Information

No response

zargham-leanix commented 2 days ago

facing the same issue while setting up @nx/vite:test for angular.