aleclarson / vite-tsconfig-paths

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

can not resolve ts files using their corresponding js extesions #54

Closed wight554 closed 1 year ago

wight554 commented 2 years ago

Support for .ts to .js alias was added in vite upstream But it doesn't work with vite-tsconfig-paths:

// from vite.config.ts
  plugins: [
    preact({
      include: '{test/,}src/**/*.{ts,tsx}',
    }),
    !isTest && tsconfigPaths(),
    !isTest &&
      checker({
        typescript: { tsconfigPath: 'src/tsconfig.json' },
        eslint: {
          lintCommand: 'eslint "./src/**/*.{ts,tsx}"',
        },
      }),
    isTest && typescript(),
  ],
// from tsconfig.json

"paths": {
  "@src/*": ["./src/*"],
  "@server/*": ["./server/*"],
  "@test/*": ["./test/*"]
},

Currently I can fix it by:

resolve: {
    alias: [{ find: /^(@.*\/.*)\.js$/, replacement: '$1.ts' }]
}

Repro can be found here: https://github.com/wight554/blog-template/pull/50

See this issue for more details: https://github.com/vitejs/vite/issues/7918

aleclarson commented 2 years ago

This is a bug in tsconfig-paths

See here: https://github.com/dividab/tsconfig-paths/pull/213

tianyingchun commented 1 year ago

Are there any temporary solutions at the moment?

wight554 commented 1 year ago

Are there any temporary solutions at the moment?

Alias, check issue description for example