question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript: IDE reports TS2307: Cannot find module error for Vue components imports

See original GitHub issue

Version

3.0.0-beta.9

Reproduction link

https://pastebin.com/N5A5uWGv

Steps to reproduce

  • Install Vue with vue-cli,
  • Choose Typescript support
  • Open any file that imports *.vue files

What is expected?

No errors are reported

What is actually happening?

IDE reports TS2307: Cannot find module error for Vue components imports. Imports are higlighted in red.


I’ve already reported this error here: https://github.com/vuejs/vue-class-component/issues/219 because I thought that it is a vue-class-component issue, but it’s not. It’s a configuration issue.

Putting the following vue-shim.d.ts declaration file under my ./src directory solves the problem:

declare module "*.vue" {
    import Vue from "vue";
    export default Vue;
}
vue-components-imports-ts

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:44
  • Comments:34 (2 by maintainers)

github_iconTop GitHub Comments

49reactions
Cookizzacommented, Sep 11, 2018

Sorry to resurrect, but this still pops up.

I’ve actually put a // @ts-ignore on it, and it’s compiling fine…

44reactions
medemancommented, Oct 14, 2019

This is happening when the .vue file extension is emitted from the import statement (i.e. import MyComponent from '@/components/MyComponent' instead of import MyComponent from '@/components/MyComponent.vue'). Haven’t figured out how to make it work without the file extension.

Read more comments on GitHub >

github_iconTop Results From Across the Web

VSCode showing "cannot find module" TS error for .vue import ...
Solution 1 (temporary hack) ... Start VS Code from inside the Vue project's root folder. (The same folder as the correct tsconfig.json .)...
Read more >
ts2307 cannot find module / import "fail" in vue files : WEB-37740
In .vue files where I use typescript, the import shows an error. e.g.. <script lang="ts"> import HokBox from '~/components/shared/HokBox.vue'; </script>.
Read more >
ts2307: cannot find module '*.vue' or its corresponding type ...
IDE reports TS2307 : Cannot find module error for Vue components imports. Imports are higlighted in red. I've already reported this error here:...
Read more >
TypeScript configuration and TS2307: Cannot find module error
The message is: TS2307: Cannot find module './components/App.vue'. Here's the code: index.js import Vue from 'vue'; import App from '.
Read more >
Cannot find module 'X' Error in TypeScript | bobbyhadz
The "Cannot find module or its corresponding type declarations" error occurs when TypeScript cannot locate a third-party or local module in our project....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found