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
Typescript cannot find module using @ root path syntax in a project created from create-vue #894
Comments
@pholly Can you give a minimal reproducible demo? Can you try to reproduce it in a new VSCode environment? For example:
|
Rolling back from 0.31.1 to v0.30.6 worked for me. |
@xiaoxiangmoe the easiest reproducable demo is to use I tried Visual Studio Code Insiders:
@olemarius rolling back to v0.30.6 didn't work for me - I still get the error in App.vue. |
@xiaoxiangmoe yes sorry I installed both extensions |
@pholly can you reproduce this problem in https://github.com/johnsoncodehk/volar-starter? |
@johnsoncodehk yes same problem. I also get an error in main.ts when using |
@pholly have you try config |
@johnsoncodehk just tried. Still same errors in both. Also the error in main.ts prevents the app from running (starting the dev server). If I fix main.ts, the site builds and runs but the error in App.vue shows up immediately in the browser. I also tried closing and reopening VS Code. Let me know if there's anything else you want me to try. |
It seems that Windows will not allow use |
@pholly I can't reproduce this problem and I think it's related to your system, please try @xiaoxiangmoe's suggestion. If still not working, you can use live share with me so I will able to check the problem. You can join volar discord server(https://discord.gg/5bnSSSSBbK) to find me. |
No errors in either main.ts or App.vue! I mistakenly put the paths line outside of compilerOptions. When I moved it there both errors went away. Yes I have to specify I still get the error in App.vue in a project created from Let me know how I should proceed - go back to my issue in create-vue project? |
@pholly if the path option generated by |
@johnsoncodehk sorry although I don't get errors when viewing main.ts or App.vue in VS Code, I get errors when trying to run the app with
Likewise I get an error in App.vue if I fix the path in main.ts to be relative. I'll reach out to you on volar's discord. Thanks for all your work and help. |
@pholly tsconfig only for IDE, you should config resolve.alias in vite.config for vite. |
@alexvoedi make sure you have add your vue files to |
Everything is set up correctly in my project. Vetur works fine, Volar does not. This has only been a problem for a few days. |
@alexvoedi could you provide minimal reproduction? |
@johnsoncodehk I have the same problem as @alexvoedi in .vue files in projects created from create-vue. tsconfig:
|
@pholly could you provide minimal reproduction? |
@xiaoxiangmoe I can't reproduce anymore - @johnsoncodehk I have no problems with projects created from create-vue now. Thank you both. |
if I have a component named |
I have this issue in a project as well. Seems like the alias works if the .vue file doing the importing is either two words, or lowercase its fine.
|
I have the same problem, i have not change any file, it was normal to open it yesterday, but now this problem happened. This is a windows10 PC, volar auto update to v0.38.7 the problem looks like:
I try there things:
As an obsessive-compulsive disorder, I feel hopeless... But in the end, I found the problem. Bad workspace, "../../tsconfig" you can see right-bottom, "tsconfig.app.json", It seems that volar read the root directory of the project incorrectly |
@gitlilimin It may related to #1193, #1262 fixing. Could you provide a minimal reproduction? |
@johnsoncodehk ok, I tried it, this problem only occur at volar 0.38.8 My environmentReproduction steps
Personal summaryI think this problem must be related to the workspace of vscode, and I'm sure it happened in volar 0.38.8 I found some phenomena in the process of trying to find the problem.
|
@gitlilimin Thank you, you saved my time. |
The vscode right-bottom "No tsconfig" maybe just caused by incorrect include config. {
"compilerOptions": {
// ...
"paths": { "@/*": ["./src/*"] } // path alias
},
"include": ["./**/*.ts", "./**/*.vue"]
} |
This is a good hint . I had same issue but now it's OK . Thanks @olemarius |
@johnsoncodehk @alexvoedi @saeedtabrizi I also had the same issue today after scaffolding a brand new project using vite, it got resolved by simply adding "moduleResolution": "node" in compilerOptions object of tsconfig.app.json |
For me it worked after I added to
|
@mitar your solution works for me too, do you know why? |
I ran into this issue with my own Volar (not Vue) project and it turned out I had to set
|
FYI i noticed for me that adding |
I've got a weird one. Originally posted in vuejs/create-vue#35
Summary
When creating a project in the new recommended way using
npm init vue@3
,@
root path imports show an error in .vue files.@
root path imports work fine inside .ts files. The strange thing is others haven't been able to reproduce my problem. See the issue mentioned above.Setup
Visual Studio code - up to date
Vue Language Features (Volar) - v0.31.1
TypeScript Vue Plugin (Volar) - v0.31.1
Windows 11
Steps to reproduce
Open App.vue and change an import to use
@/
root path syntax. E.g.import TheWelcome from '@/components/TheWelcome.vue'
. I get an error:Cannot find module '@/components/TheWelcome.vue' or its corresponding type declarations.ts(2307)
Things I tried
The text was updated successfully, but these errors were encountered: