aleclarson / vite-tsconfig-paths

Support for TypeScript's path mapping in Vite
MIT License
1.28k stars 45 forks source link

Transitive dependencies are not resolved #47

Closed realityfilter closed 2 years ago

realityfilter commented 2 years ago

I have the same problem described in issue #12 which is closed. An example repository can be found here: https://github.com/realityfilter/bug-transitive-deps

the structure is app: uses liba liba: uses libb libb

Just run nx serve app Resulting in the error:

  The following dependencies are imported but could not be resolved:
  @trans-dep/libb (imported by /Users/vb/Desktop/nx-vite-dep/trans-dep/packages/liba/src/lib/liba.ts)

I tried the workaround described in issue #12:

tsconfigPaths({
  root: '../..',
})

with no success.

aleclarson commented 2 years ago

what do the debug logs say?

DEBUG="vite-tsconfig-paths" vite
realityfilter commented 2 years ago
> nx run app:serve

2022-02-22T18:08:05.762Z vite-tsconfig-paths crawling "/path/Desktop/trans-dep"
2022-02-22T18:08:05.764Z vite-tsconfig-paths options: {
  projects: [
    '/path/Desktop/trans-dep/packages/app/tsconfig.json',
    '/path/Desktop/trans-dep/packages/liba/tsconfig.json',
    '/path/Desktop/trans-dep/packages/libb/tsconfig.json'
  ],
  extensions: [ '.ts', '.tsx', '.js', '.jsx', '.mjs' ]
}
2022-02-22T18:08:05.768Z vite-tsconfig-paths config loaded: {
  configPath: '/path/Desktop/trans-dep/packages/app/tsconfig.json',
  include: [],
  exclude: [ 'node_modules', 'tmp' ],
  allowJs: undefined,
  baseUrl: '/path/Desktop/trans-dep',
  paths: {
    '@trans-dep/liba': [ 'packages/liba/src/index.ts' ],
    '@trans-dep/libb': [ 'packages/libb/src/index.ts' ]
  },
  outDir: undefined
}
2022-02-22T18:08:05.768Z vite-tsconfig-paths compiled globs: {
  included: [],
  excluded: [
    /^\.\/node_modules\/((?:[^/]*(?:\/|$))*)$/,
    /^\.\/tmp\/((?:[^/]*(?:\/|$))*)$/
  ]
}
2022-02-22T18:08:05.769Z vite-tsconfig-paths config loaded: {
  configPath: '/path/Desktop/trans-dep/packages/liba/tsconfig.json',
  include: [],
  exclude: [ 'node_modules', 'tmp' ],
  allowJs: undefined,
  baseUrl: '/path/Desktop/trans-dep',
  paths: {
    '@trans-dep/liba': [ 'packages/liba/src/index.ts' ],
    '@trans-dep/libb': [ 'packages/libb/src/index.ts' ]
  },
  outDir: undefined
}
2022-02-22T18:08:05.769Z vite-tsconfig-paths compiled globs: {
  included: [],
  excluded: [
    /^\.\/node_modules\/((?:[^/]*(?:\/|$))*)$/,
    /^\.\/tmp\/((?:[^/]*(?:\/|$))*)$/
  ]
}
2022-02-22T18:08:05.770Z vite-tsconfig-paths config loaded: {
  configPath: '/path/Desktop/trans-dep/packages/libb/tsconfig.json',
  include: [],
  exclude: [ 'node_modules', 'tmp' ],
  allowJs: undefined,
  baseUrl: '/path/Desktop/trans-dep',
  paths: {
    '@trans-dep/liba': [ 'packages/liba/src/index.ts' ],
    '@trans-dep/libb': [ 'packages/libb/src/index.ts' ]
  },
  outDir: undefined
}
2022-02-22T18:08:05.771Z vite-tsconfig-paths compiled globs: {
  included: [],
  excluded: [
    /^\.\/node_modules\/((?:[^/]*(?:\/|$))*)$/,
    /^\.\/tmp\/((?:[^/]*(?:\/|$))*)$/
  ]
}
2022-02-22T18:08:05.771Z vite-tsconfig-paths options: {
  projects: [
    '/path/Desktop/trans-dep/packages/app/tsconfig.app.json'
  ],
  extensions: [ '.ts', '.tsx', '.js', '.jsx', '.mjs' ]
}
2022-02-22T18:08:05.772Z vite-tsconfig-paths config loaded: {
  configPath: '/path/Desktop/trans-dep/packages/app/tsconfig.app.json',
  include: [ '**/*.ts' ],
  exclude: [ '**/*.spec.ts', '**/*.test.ts' ],
  allowJs: undefined,
  baseUrl: '/path/Desktop/trans-dep',
  paths: {
    '@trans-dep/liba': [ 'packages/liba/src/index.ts' ],
    '@trans-dep/libb': [ 'packages/libb/src/index.ts' ]
  },
  outDir: '../../dist/out-tsc'
}
2022-02-22T18:08:05.772Z vite-tsconfig-paths compiled globs: {
  included: [ /^\.\/((?:[^/]*(?:\/|$))*)([^/]*)\.ts$/ ],
  excluded: [
    /^\.\/((?:[^/]*(?:\/|$))*)([^/]*)\.spec\.ts$/,
    /^\.\/((?:[^/]*(?:\/|$))*)([^/]*)\.test\.ts$/,
    /^\.\.\/\.\.\/dist\/out-tsc\/((?:[^/]*(?:\/|$))*)$/
  ]
}
2022-02-22T18:08:05.805Z vite-tsconfig-paths resolved: {
  id: '@trans-dep/liba',
  importer: '/path/Desktop/trans-dep/packages/app/src/main.ts',
  resolvedId: '/path/Desktop/trans-dep/packages/liba/src/index.ts',
  configPath: '/path/Desktop/trans-dep/packages/app/tsconfig.app.json'
}
The following dependencies are imported but could not be resolved:

  @trans-dep/libb (imported by /path/Desktop/trans-dep/packages/liba/src/lib/liba.ts)

Are they installed?
aleclarson commented 2 years ago

Could you please reproduce the issue in a Stackblitz or the ./demo folder of this repo (then open a PR)?

So I can debug easier :)

realityfilter commented 2 years ago

There were two problems in our nx workspace:

So no bug, can be closed.

Maximilianos commented 2 years ago

I ran into this as well and have posted how I resolved it based on the notes in this thread and elsewhere in the following issue: https://github.com/aleclarson/vite-tsconfig-paths/issues/12#issuecomment-1081160667

aleclarson commented 1 year ago

Note that Nx monorepos will be supported without workarounds in v4 of the plugin 🎉