I'm working in a Vue.js project that uses Webpack. Many imports use @
as an alias to src
directory. How can VSCode be configured to resolve the alias and make intellisense work with those imports?
I have found in many places on the web how to setup aliases in VSCode, using jsconfig.json
or tsconfig.json
. I have tried configuring in both files and nothing seems to work.
My jsconfig.json:
{
"compilerOptions": {
"target": "es6",
"allowSyntheticDefaultImports": false,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"exclude": ["node_modules", "dist"]
}
I expected VSCode to resolve the alias in the path, making intellisense and peeking definition work.
If you are using the VS, Please go to the settings .. search for Advance path and then ADD it (/. source) it should solve the problem. Hope you have installed the Pylance in your system correctly.
You may have installed the libraries inside a virtual environment and you are using a python interpreter that is not inside the environment. Edit: It could be that just one of your libraries is inside (or outside) the environment.
In VSCode, go to File -> Preferences -> Settings and click on the icon in the top right hand corner to open up the settings in JSON. Et voilà! Your imports will now be organized every time you save a file.
In my current project, I have a jsconfig.json
at the root containing this :
{
"compilerOptions": {
"target": "es2017",
"allowSyntheticDefaultImports": false,
"baseUrl": "./",
"paths": {
"@/*": ["src/*"],
}
},
"exclude": ["node_modules", "dist", "docs"]
}
and it works for me.
I don't know exactly what moduleResolution
is doing in your conf, and my baseUrl
is the root folder in my case.
The related doc for vs code : https://code.visualstudio.com/docs/languages/jsconfig#_using-webpack-aliases
Try it and tell me if it's working better ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With