[bug] `File could not be loaded` with `resolve.extensions: ['.vue', '.ts']`
See original GitHub issue⚠️ IMPORTANT ⚠️ Please check the following list before proceeding. If you ignore this issue template, your issue will be directly closed.
- Read the docs.
- Use Vite >=2.0. (1.x is no longer supported)
- If the issue is related to 1.x -> 2.0 upgrade, read the Migration Guide first.
Describe the bug
Exception error: File could not be loaded
is thrown when using resolve.extensions: ['.vue', '.ts']
with import MyComponent from './my-component' // without .vue extension
yarn run v1.22.10
warning package.json: No license field
$ vite
> html:/Users/Carter/vite-bug/src/App.vue: error: File could not be loaded: src/v-text.vue
2 │ import VText from './v-text';
╵ ~~~~~~~~~~
error when starting dev server:
Error: Build failed with 1 error:
html:/Users/Carter/vite-bug/src/App.vue:2:18: error: File could not be loaded: src/v-text.vue
at failureErrorWithLog (/Users/Carter/vite-bug/node_modules/esbuild/lib/main.js:1170:15)
at buildResponseToResult (/Users/Carter/vite-bug/node_modules/esbuild/lib/main.js:906:32)
at /Users/Carter/vite-bug/node_modules/esbuild/lib/main.js:1001:20
at /Users/Carter/vite-bug/node_modules/esbuild/lib/main.js:553:9
at handleIncomingPacket (/Users/Carter/vite-bug/node_modules/esbuild/lib/main.js:642:9)
at Socket.readFromStdout (/Users/Carter/vite-bug/node_modules/esbuild/lib/main.js:520:7)
at Socket.emit (node:events:378:20)
at addChunk (node:internal/streams/readable:313:12)
at readableAddChunk (node:internal/streams/readable:288:9)
at Socket.Readable.push (node:internal/streams/readable:227:10)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I saw the note about custom import types. It was NOT recommended
instead of NOT allowed
so I believed that using resolve.extensions: ['.vue']
should work by design.
Reproduction
https://github.com/CarterLi/vite-bug
yarn && yarn dev
System Info
vite
version: 2.0.1- Operating System: macOS 11.2
- Node version: v15.9.0
- Package manager (npm/yarn/pnpm) and version: yarn 1.22.10
Logs (Optional if provided reproduction)
N/A
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
webpack - I get following error when I import *.vue files without ...
The problem is in your Webpack configuration. To make Webpack automatically resolve .vue extensions use the resolve.extensions option, ...
Read more >Features | Vite
Vite provides first-party HMR integrations for Vue Single File Components and ... Vite only performs transpilation on .ts files and does NOT perform...
Read more >User Guide | eslint-plugin-vue
Make sure your tool is set to lint .vue files. CLI targets only .js files by default. You have to specify additional extensions...
Read more >API - ESBuild
In node, you can load a module using node --experimental-modules file.mjs . Note that node requires the .mjs extension unless you have configured...
Read more >fork-ts-checker-webpack-plugin - npm
It's because of the performance - with TypeScript's module resolution we don't have to wait for webpack to compile files. To debug TypeScript's ......
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 Free
Top 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
How do I retrofit an existing project to use Vite, since I developed my own business component library and released the NPM package with the omission of the Vue extension
This should work technically, but again, DON’T USE IT. All future Vue APIs / ecosystem tooling will all assume explicit extensions for
.vue
imports. You are just creating incompatibility and writing less explicit code for no good reason.