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.

Cannot find module (TS2307)

See original GitHub issue

Created 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:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

49reactions
avxkimcommented, Oct 17, 2019

It was because of missing Vue module declaration, i’ve created ts-shim.d.ts file in the root directory:

declare module '*.vue' {
  import Vue from 'vue'
  export default Vue
}

Please, update your documentation, so other won’t struggle with this: https://typescript.nuxtjs.org/guide/setup.html

38reactions
boredlandcommented, Apr 5, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found