Skip to content
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

The import-x/no-unresolved rule conflicts with the alias of the vite alias path #215

Open
WZDreamJiao opened this issue Dec 20, 2024 · 5 comments

Comments

@WZDreamJiao
Copy link

WZDreamJiao commented Dec 20, 2024

I am very sorry to bother you. During the project construction process, I used eslint-plugin-import-x to make import rules, and used resolve.alias to configure path aliases in the vite configuration file. Unfortunately the import - x/no - unresolved this rule, does not identify the import HelloWorld from '@ / components/HelloWorld. Vue' the introduction of this path, I was looking for, but didn't find effective solution, Sorry to bother you again

@WZDreamJiao
Copy link
Author

package.json:
"eslint-import-resolver-typescript": "^3.7.0",
"eslint-plugin-import-x": "^4.5.0",

vite.config.ts:
export default defineConfig({
plugins: [vue(), Unocss()],
resolve: {
alias: {
'@/': resolve('src/'),
},
},
})

eslint.config.js:
{
rules: {
'import-x/no-nodejs-modules': [
'error',
{ allow: builtinModules.map(mod => node:${mod}) },
],
'import-x/no-unresolved': ['error', { ignore: ['^virtual:'] }],
},
},
{
// Have no effect
settings: {
'import/resolver-next': [
createTypeScriptImportResolver({
project: 'tsconfig.json',
alias: {
'@/': './src/',
},
extensions: ['.js', '.ts', '.vue'],
}),
],
},
},

App.vue:

<script setup lang="ts"> import HelloWorld from '@/components/HelloWorld.vue' </script>

Error:
Unable to resolve path to module '@/components/HelloWorld.vue'.eslint[import-x/no-unresolved]

@SukkaW
Copy link
Collaborator

SukkaW commented Dec 20, 2024

@WZDreamJiao Have you tried this import resolver for vite alias? https://github.com/pzmosquito/eslint-import-resolver-vite

@WZDreamJiao
Copy link
Author

@SukkaW Thank you very much. It works. I'll look into how it works. Thank you very much

@SukkaW
Copy link
Collaborator

SukkaW commented Dec 20, 2024

You can have multiple resolvers enabled all at once with import-x/resolver-next options, and the resolver should execute in order.

@WZDreamJiao
Copy link
Author

@SukkaW yes,thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants