Thiago R.
Thiago R.
Explore posts from servers
KPCKevin Powell - Community
Created by Thiago R. on 9/27/2024 in #os-and-tools
Can't set absolute paths to Vite Project
Hello I was trying to make sure I could use either typescript namespaces and use absolute file paths for import statements, as this how-to article suggests. my tsconfig.json file is as follows:
{
"files": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.node.json"
}
],
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@src/*": ["./src/*"],
"@data/*": ["./src/data/*"],
"@views/*": ["./src/views/*"],
"@services/*": ["./src/services/*"]
}
}
}
{
"files": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.node.json"
}
],
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@src/*": ["./src/*"],
"@data/*": ["./src/data/*"],
"@views/*": ["./src/views/*"],
"@services/*": ["./src/services/*"]
}
}
}
Also, my vite.config.ts file is as follows:
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
plugins: [react(), tsconfigPaths()],
resolve: {
alias: {
'@src': '/src',
'@data': '/src/data',
'@views': '/src/views',
'@services': '/src/services',
},
},
});
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
plugins: [react(), tsconfigPaths()],
resolve: {
alias: {
'@src': '/src',
'@data': '/src/data',
'@views': '/src/views',
'@services': '/src/services',
},
},
});
However, if I try to use the absolute paths like the following:
import { ErrorPage } from 'src/views/pages'
import { ErrorPage } from 'src/views/pages'
For instance, the project is a react/tsx game catalogue. The mentioned files are already committed there. The editor doesn't recognize it. For instance, I'm using Jetbrains Webstorm. Has anyone here ever have been through this situation?
2 replies