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 cannot find module using @ root path syntax in a project created from create-vue

See original GitHub issue

I’ve got a weird one. Originally posted in https://github.com/vuejs/create-vue/issues/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

npm init vue@3
Typescript support: yes
Everything else: no

pnpm install (or npm install)

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)

image

Things I tried

  • Disabling all other plugins
  • Uninstalling/reinstalling Volar plugins
  • Enabled Take Over Mode

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:35 (8 by maintainers)

github_iconTop GitHub Comments

5reactions
xiaoxiangmoecommented, Jan 26, 2022

It seems that Windows will not allow use "paths": { "@/*":["src/*"] },, try change it to "paths": { "@/*":["./src/*"] },.

4reactions
phollycommented, Jan 28, 2022

@johnsoncodehk I have the same problem as @alexvoedi in .vue files in projects created from create-vue. "src/**/*.vue" is definitely in include in tsconfig.

tsconfig:

{
  "compilerOptions": {
    "baseUrl": "./",
    "target": "esnext",
    "useDefineForClassFields": true,
    "module": "esnext",
    "moduleResolution": "node",
    "isolatedModules": true,
    "strict": true,
    "jsx": "preserve",
    "sourceMap": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "paths": {
      "@/*": ["src/*"]
    },
    "lib": ["esnext", "dom", "dom.iterable", "scripthost"],
    "skipLibCheck": true
  },
  "include": ["vite.config.*", "env.d.ts", "src/**/*", "src/**/*.vue"]
}
image
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot find module 'path' Error in TypeScript | bobbyhadz
To solve the "Cannot find module path or its corresponding type declarations" error, install the types for node by running the command npm...
Read more >
TypeScript 'cannot find module...' in Vue project - Stack Overflow
Try adding the following into index.d.ts in the project root, works for now. declare module '*.vue' { import Vue from 'vue' export default ......
Read more >
cannot find module 'path' or its corresponding type ... - You.com
When creating a new app with TypeScript, any imports using absolute path syntax '@/' show as errors in Visual Studio Code with the...
Read more >
Vue.js | WebStorm Documentation - JetBrains
js app is the create-vue official Vue project scaffolding tool, which WebStorm downloads and runs for you using npx. You can still use...
Read more >
How To Generate a Vue.js Single Page App With the Vue CLI
vue create vue-starter-project. The highlighted section of the command is the name of the root directory of the 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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found