Closed angeliski closed 5 years ago
Your import path in src/views/Home.vue
is wrong. Use import import HelloWorld from '@/components/HelloWorld.vue'
instead of HelloWorld from 'components/HelloWorld.vue'
Hi @kefranabg My import it's not wrong, since I tried use the webpack to resolve that extension: https://webpack.js.org/configuration/resolve/#resolve-extensions
The webpack config use this option how you can see that: https://github.com/vuejs/vue-cli/blob/e7af0d8fa374311693f14d1605e7ae442e43c3a6/packages/%40vue/cli-service/lib/config/base.js#L39-L41
I wrong about that? Can you explain better your comment? I'm not expert about, maybe I miss something
I think is a bug for vue-cli-service because the webpack config is provided, if the issue is for the webpack let me know
the extension is not the issue. the path is wrong:
import HelloWorld from 'components/HelloWorld.vue';
This makes webpack / eslint look for a package named components
in the /node_modules
directory - which of course doesn't exist.
You either need to provide a relative path:
import HelloWorld from '../components/HelloWorld.vue';
Or use the special @/
shortcut to make the path relative to the /src
directory:
import HelloWorld from '@/components/HelloWorld.vue';
Ow, sorry @LinusBorg and @kefranabg I make the code wrong, but I do some tests before commit and forget the return the code to original problem. Really sorry about that. I update the repository, now is "correct":
Removed extension .vue and update the reference to @/ how expected
Now it's another error (Missing file extension "vue" for "@/components/HelloWorld" (import/extensions)
) and I think it works as expected
Thank you for support @sodatea , My problem is not solved but I see that it's not a bug.
Cheers
you can solve your problem by extending the original config in your own .eslintrc file:
{
// other stuff
"settings": {
"import/resolver": {
"import/extensions": [
".js",
".jsx",
".mjs",
".ts",
".tsx",
".vue"
]
}
}
}
Thanks for answer @LinusBorg That worked. Sorry for the issue, I will learn more about Webpack before open another issue
Cheers
For me, on vue-cli 3.5.0, it was extending the .eslintrc.js file:
...
rules: {
// other stuff
'import/extensions': ['error', 'always', {
js: 'never',
mjs: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never',
vue: 'never'
}]
},
...
@LinusBorg since older vue-cli generated websites didn't specify .vue in the end of component files, why not adding by default the related eslint rule out of the box? (since webpack correctly resolves the files without specifying the extension anyway, seems a bit confusing to not have the rule) (I can make a PR if OK)
The solution is to disable eslint for all the import statements.
/*eslint-disable */
import DashboardLayout from '../layouts/DashboardLayout';
after all import statements, you enable eslint. /eslint-enable /
This problem is peculiar to airbnb eslint preset.
You saved my life men! Quick and efficient
Version
3.3.0
Reproduction link
https://github.com/angeliski/vue-cli-typescript-lint-error-extension
Environment info
Steps to reproduce
npm install
npm run lint
What is expected?
No errors
What is actually happening?
error: Unable to resolve path to module 'components/HelloWorld.vue' (import/no-unresolved) at src/views/Home.vue:10:24:
I see the issue #2628, but not works how expected. When I make the same steps in a project without Typescript the error happen in
npm run lint
but no innpm run serve