Skip to content
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

When import .vue inside .js file it gives module not found in vscode #1322

Closed
3 tasks done
sagarrabadiya opened this issue Jun 7, 2019 · 10 comments
Closed
3 tasks done

Comments

@sagarrabadiya
Copy link

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ

Info

  • Platform: Win
  • Vetur version: 0.21.0
  • VS Code version: 1.35.0

Problem

When .vue file is imported from .js file and checkJs is true in jsconfig.json file vscode gives error that it can't find module even though .vue extension is included in the import please check the screenshot.

vetur-problem

Reproducible Case

Just create new app using vue-cli and in main.js try to ctrl + click on App.vue import it doesn't take me to the App.vue file.

@yoyo930021
Copy link
Member

You need to add one file.
see https://github.com/microsoft/TypeScript-Vue-Starter/blob/master/README.md#single-file-components.

@sagarrabadiya
Copy link
Author

Hi @yoyo930021 I have tried by adding vue-shims.d.ts but when I add vue-shims.d.ts file the module not found error is gone but the problem is when I try to find the module definition or try ctrl + click on the imported component it doesn't take me to the .vue file instead it shows the ts declared module as definition please check the screenshot
image

@yoyo930021
Copy link
Member

jsconfig.json content?

@sagarrabadiya
Copy link
Author

@yoyo930021 here is the jsconfig.json content

{
  "include": ["./src/**/*"],
  "compilerOptions": {
    "module": "es6",
    "moduleResolution": "node",
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    },
    "checkJs": true
  },
  "exclude": ["node_modules"]
}

@yoyo930021
Copy link
Member

I think it's a problem.
The .ts file have the same problem.

@sagarrabadiya
Copy link
Author

sagarrabadiya commented Jun 8, 2019

Yes exactly, if i ctrl + click from .vue file then it works, meaning if i import .vue file inside .vue file's script tag then it navigates correctly but if .vue file is imported in .js or .ts file then it can't detect that module as .vue component

@yoyo930021
Copy link
Member

yoyo930021 commented Jun 8, 2019

When use .ts or .js files, VSCode use typescript-language-server in VSCode built-in.
It don't know .vue file, It use vue-shims.d.ts file to know.

When use .vue files, VSCode use vue-language-server in vetur.
It can know .vue file by itself, so can get more info.

The above is my guess.

@octref
Copy link
Member

octref commented Jun 19, 2019

Depends on #673, for now you can take a look at https://github.com/HerringtonDarkholme/vue-ts-plugin.

@huoyuxin
Copy link

huoyuxin commented Jun 9, 2021

it just can not recognize and go to the definition the .vue import in .js / .ts
so, there is a little trick:
you can change .js / .ts to .vue, and use <script lang="ts"></script> to wrap the .vue import code, then everything goes perfect

@Joe-Joi
Copy link

Joe-Joi commented Jun 25, 2021

for me, adding '.vue' extention is the only solution: import App from "./App.vue";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants