-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] File could not be loaded
with resolve.extensions: ['.vue', '.ts']
#2163
Comments
No matter whether this should work or not, just FYI: support for omitting |
It's supported with the similar way // vue.config.js
config.resolve.extensions
.clear()
.merge(['.vue', '.tsx', '.ts', '.mjs', '.js', '.jsx', '.json', '.wasm']); The document says it IS supported so it SHOULD work. It is NOT a feature request but a bug. |
This is why I want to omitting The type system of declare module '*.vue' {
import { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
} You can never access data / methods of a component in a properly way. <!-- my-component.vue -->
<template>...</template>
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
name: 'MyComponent',
methods: {
test(param: string) {},
},
})
</script> import MyComponent from './my-component.vue';
export default {
components: { MyComponent },
methods: {
test() {
(this.$refs.myComponent as typeof MyComponent).test(''); // No type checking, no IDE intelligence
}
}
} That makes TypeScript less powerful. But omitting <template>...</template>
<script lang="ts" src="./my-component.ts" /> // my-component.ts
import { Vue, Options } from 'vue-class-component'
@Options()
export default class MyComponent extends Vue {
test(param: string) {}
} import MyComponent from './my-component'; // imports the value of `my-component.vue`, with the type of `my-compnoent.ts`
export default {
components: { MyComponent },
methods: {
test() {
(this.$refs.myComponent as MyComponent).test(''); // type checking, and IDE intelligence
}
}
} |
This should work technically, but again, DON'T USE IT. All future Vue APIs / ecosystem tooling will all assume explicit extensions for |
Better TypeScript support is a good reason IMO. I know it's a hack, but before |
@CarterLi both |
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 |
@zhaozhuoboy comments in old issues are probably going to be ignored. Please start a GitHub Discussion or join the chat at Vite Land to ask questions. |
Any tip to help someone who is refactoring to vue3 with vite? |
Describe the bug
Exception
error: File could not be loaded
is thrown when usingresolve.extensions: ['.vue', '.ts']
withimport MyComponent from './my-component' // without .vue extension
I saw the note about custom import types. It was
NOT recommended
instead ofNOT allowed
so I believed that usingresolve.extensions: ['.vue']
should work by design.Reproduction
https://github.com/CarterLi/vite-bug
yarn && yarn dev
System Info
vite
version: 2.0.1Logs (Optional if provided reproduction)
N/A
The text was updated successfully, but these errors were encountered: