I used Vite to scaffold a typescript-react project, and i wanted to use the given tsconfig.json
file to create shortcuts for my directories, so i wont have to deal with long relative paths when importing stuff in my components.
This is tsconfig.json
:
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"baseUrl": "./src",
"paths": {
"@styles/*": ["styles/*"],
"@routes/*": ["routes/*"],
"@components/*": ["components/*"],
"@assets/*": ["assets/*"]
}
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
I get an error when trying to import LandingPage.module.css
into my component LandingPage.tsx
using this line : import styles from "@styles/LandingPage.module.css";
here's the relevant folder structure :
The Intellisense in VS Code when i type import styles from "@styles/"
shows only the js file in styles
folder, and doesn't pick up on the css module.
Attempted solution :
A comment about restarting the Typescript server, didn't work.
Ref : This SO question
tsconfig.json
that looks like:"@/*": ["./src/*"]
, and my import in atsx
file referencing'@/styles/Home.module.css'
(which exists) fails with "Cannot find module..." I've done the similar types of things, restarted the TS language server, etc. and the error persists. – Littlest