Error when importing components without .vue extension in TypeScript
See original GitHub issueVersion
Reproduction link
https://codesandbox.io/s/zrl1qrlo3p
Steps to reproduce
Go to the CodeSandbox reproduction link and open the terminal window.
What is expected ?
Resolve .vue files without throwing errors in the terminal.
What is actually happening?
It resolves .vue files but still throws an error in the terminal.
ERROR in ~/pages/index.vue
Cannot find module '~/components/HelloWorld'.
import HelloWorld from "~/components/HelloWorld";
<div align="right">This bug report is available on Nuxt community (#c8696)</div>Issue Analytics
- State:
- Created 5 years ago
- Comments:8
Top Results From Across the Web
How to remove .vue extension from imports when using ...
the compiler throwing an error in "Cannot find module '@/components/HelloWorld'";. The component HelloWorld exists. However, if I remove the ...
Read more >TypeScript unable to locate module (vue file) when trying to ...
It turns out TypeScript will not recognize Vue files without adding the ".vue" extension in the path when importing. I will need to...
Read more >Features | Vite
TypeScript #. Vite supports importing .ts files out of the box. Vite only performs transpilation on .ts files and does NOT perform ...
Read more >Evan You on Twitter: "@murilobd You should always use the ...
You should always use the .vue extension when importing Vue components, as omitting the extension creates numerous problems for static analysis ...
Read more >An import path cannot end with a '.tsx' extension in TS
The error "An import path cannot end with a '.tsx' extension" occurs when we include the extension when importing TypeScript files in a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
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
@cretueusebiu Alright, I indeed have been able to see the error by triggering a change.
Well you need to add
.vue
extension when importing Vue SFC’s.Implicit module imports (not providing extension of the imported module) should (IMO) only be done for
.js
&.ts
extensions.HelloWorld.js
=>import HelloWorld from "~/components/HelloWorld";
HelloWorld.ts
=>import HelloWorld from "~/components/HelloWorld";
HelloWorld.vue
=>import HelloWorld from "~/components/HelloWorld.vue";
If the extension is implicit, I guess it can’t be handled properly by the
ts-loader
used to handle Vue SFC with TS. And there isn’t workaround (As far as I know) other than providing the.vue
extension in the import statement.@cretueusebiu It’s cause of the TypeChecker which run in seperate process. See https://github.com/Realytics/fork-ts-checker-webpack-plugin#vue
I’m closing this issue as it’s documented in the TypeChecker documentation.