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.

Import typescript file with alias in path into vue component.

See original GitHub issue
  • [ x ] I have searched through existing issues
  • [ x ] I have read through docs
  • [ x ] I have read FAQ

Info

  • Platform: macOS
  • Vetur version: 0.22.4
  • VS Code version: 1.32.1 (1.32.1)

Problem

Error in .vue file during import .ts file with alias in path. File is imported correctly but editor mark line with import.

Relative path without an error

Zrzut ekranu 2019-10-17 o 11 03 24

Path with alias with an error.

Zrzut ekranu 2019-10-17 o 11 03 45

Please note that other files are imported without any error.

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": ["webpack-env", "types/globalTypes.ts"],
    "paths": {
      "@/*": ["src/*"]
    },
    "lib": ["esnext", "dom", "dom.iterable", "scripthost"]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": ["node_modules"]
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
yoyo930021commented, Nov 7, 2020

Hello everyone, Vetur is support this feature now. Please keep tsconfig.json in project root. Remember set compilerOption.paths. and than restart vue language server or restart VSCode.

0reactions
luan-orlandi-ifoodcommented, Apr 23, 2021

For anyone still struggling with this, In my case, what worked was by inserting the .vue format at the of the import, then the error was gone

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can one use a path alias in *.vue component imports ...
When I work with Vue single file components in Vite I can use a baseUrl and path alias in tsconfig.json to import *.ts...
Read more >
Import TS file in Vue component via alias (Cannot find ...
When I import vue file - all works fine. But when I'm trying import ts file with path alias then IDE shows error...
Read more >
Vue.js+Typescript: tsconfig.json path aliases not resolved ...
Vue.js+Typescript: tsconfig.json path aliases not resolved in .vue files ... recognize folder containing JS .vue file when importing from TS .vue file.
Read more >
Documentation - Module Resolution
A relative import is resolved relative to the importing file and cannot resolve to an ambient module declaration. You should use relative imports...
Read more >
Aliases | Laravel Mix Documentation
Path aliases are useful when you want to include files from a particular directory but do so from many others without repeatedly writing...
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