问题似乎是我在
TypeScript和
baseUrl
(paths
) 中设置了 alias
。
"baseUrl": ".",
"paths": {
"screens/*": ["./src/screens/*"],
"components/*": ["./src/components/*"]
}
为了让它工作,我还必须配置 Vite:
vite.config.ts
export default defineConfig({
plugins: [react()],
resolve:{
alias:{
screens: path.resolve(__dirname, './src/screens'),
components: 'src/components',
}
}
})
使用时
npm run build
产生以下错误:
[vite:load-fallback] Could not load src/components/tables/MainTable (imported by src/screens/Home.tsx): ENOENT: no such file or directory, open 'C:\Users\USER\Documents\proyect-test\src\components\tables\MainTable'
error during build:
Error: Could not load src/components/tables/MainTable (imported by src/screens/Home.tsx): ENOENT: no such file or directory, open 'C:\Users\USER\Documents\proyect-test\src\components\tables\MainTable'
这个项目很小,作为例子使用
尝试将其更改为以下内容:
export default defineConfig({
plugins: [react()],
resolve:{
alias:{
screens: '/src/screens',
components: '/src/components',
}
}
})
这可能与本地存储库和远程存储库的文件或文件夹名称区分大小写不一致有关。