Cannot find module (TS2307)
See original GitHub issueCreated nuxt project using npx
Contents of tsconfig.json:
// tsconfig.json
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"lib": ["esnext", "esnext.asynciterable", "dom"],
"esModuleInterop": true,
"allowJs": true,
"sourceMap": true,
"strict": true,
"noEmit": true,
"baseUrl": ".",
"paths": {
"~/*": ["./*"],
"@/*": ["./*"]
},
"types": ["@types/node", "@nuxt/types"]
},
"exclude": ["node_modules"]
}
Index.vue (where i face import issue):
<script lang="ts">
import Logo from '~/components/Logo.vue'
export default {
components: {
Logo
}
}
</script>
Component successfully imports, but TS server reports an error Error:(28, 18) TS2307: Cannot find module '~/components/Logo.vue'.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
tsc throws `TS2307: Cannot find module` for a local file
Visual Studio threw this error because it refused to resolve the include path of a local package. Three hours later, comparing module versions...
Read more >"TS2307: Cannot find module" error displayed while project ...
the problem is that the include pattern is specified incorrectly, thus no .ts files are included. As no tsconfig.json ts files are included...
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 >TS2307: Cannot find module or its corresponding type ...
Hi there. I'm currently developing custom github action with typescript and I want to use npm package inside of action project.
Read more >TIL: TypeScript | Fix "TS2307: Cannot find module 'src' or its ...
Story After I updated my package.json and installed all dependencies, my npm run build... Tagged with todayilearned, typescript, vue, npm.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It was because of missing Vue module declaration, i’ve created ts-shim.d.ts file in the root directory:
Please, update your documentation, so other won’t struggle with this: https://typescript.nuxtjs.org/guide/setup.html
Is this still state of the art? I think it should be noted in the docs, that your imports have to be suffixed “.vue” for this to work.