-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
importing aliased ts files using their corresponding js extesions fails #7918
Comments
Was reported here as well: #6671 (comment) |
It worked if I change the config like below. /// <reference types="vitest" />
import path from 'path';
import preact from '@preact/preset-vite';
import { defineConfig } from 'vite';
import checker from 'vite-plugin-checker';
import typescript from 'vite-plugin-typescript';
import tsconfigPaths from 'vite-tsconfig-paths';
import { configDefaults } from 'vitest/config';
const isTest = process.env.NODE_ENV === 'test';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
preact({
include: '{test/,}src/**/*.{ts,tsx}',
}),
- !isTest && tsconfigPaths(),
!isTest &&
checker({
typescript: { tsconfigPath: 'src/tsconfig.json' },
eslint: {
lintCommand: 'eslint "./src/**/*.{ts,tsx}"',
},
}),
isTest && typescript(),
],
build: {
outDir: path.join(__dirname, 'dist/public'),
emptyOutDir: true,
},
test: {
environment: 'jsdom',
globals: true,
coverage: {
exclude: [...configDefaults.coverage.exclude, '**/schemas/**'],
},
setupFiles: ['test/testSetup.ts', 'test/recoilTestSetup.ts'],
},
resolve: {
- alias: !isTest && [{ find: /^(@.*\/.*)\.js$/, replacement: '$1.ts' }],
+ alias: !isTest && [
+ {
+ find: '@src',
+ replacement: path.resolve(__dirname, 'src'),
+ },
+ ],
},
}); It seems it's a bug in Closing as it is not a bug in Vite. Please create a minimal reproduction if you think it is a bug in vite. |
please check config example from bug description, it's broken when used with relative paths, eg if i change your example this way:
|
So if there is The error is a bit confusing though (related: #5813). |
Describe the bug
Support for .ts to .js alias was added in #5510 and #7005.
But it doesn't really work when using with typescript path alias:
Currently I can fix it by:
Reproduction
wight554/blog-template#50
System Info
Used Package Manager
yarn
Logs
Validations
The text was updated successfully, but these errors were encountered: