pzmosquito / eslint-import-resolver-vite

Vite module resolution plugin for eslint-plugin-import.
MIT License
16 stars 4 forks source link

`imort/no-unresolved`: Unable to resolve path to module '/assets/filename' #19

Closed n0099 closed 8 months ago

n0099 commented 9 months ago

reprod: https://github.com/n0099/open-tbm/blob/81200597d50d9f2a6b9dd59f07ca6a5226c20e25/fe/src/components/placeholders/PlaceholderPostList.vue#L21 It's similar to #7 but these files are placed under /assets following https://vitejs.dev/guide/assets so shouldn't get reported.

pzmosquito commented 8 months ago

Thanks for providing the repo. I don't see this plugin in the codebase, did I miss anything there?

n0099 commented 8 months ago

comment this line out https://github.com/n0099/open-tbm/blob/81200597d50d9f2a6b9dd59f07ca6a5226c20e25/fe/.eslintrc.cjs#L38 or checkout to the latest commit https://github.com/n0099/open-tbm/blob/89ad27cebad06c5bdfe20ff4fdf5ebebbf3bbbad/fe/src/components/placeholders/PlaceholderPostList.vue#L21

pzmosquito commented 8 months ago

I tried the same set up as yours

/vite.config.js
/assets/test.jpg
/src/App.jsx

When I do import image from '/assets/test.jpg';, This resolver didn't throw error but the node resolver did. So the import/no-unresolved error reported was not triggered by this resolver but the node resolver.

eslint-plugin-import:resolver:node resolve threw error: Error: Cannot find module '/assets/test.jpg' from '/src/App.jsx'

UPDATE: the import/no-unresolved error is actually caused by both this resolver and node resolver weren't able to resolve the path. I will investigate more on this.

pzmosquito commented 8 months ago

@n0099 I fixed some issues for resolving absolute import. Can you give 2.0.0-beta.3 a try?

n0099 commented 8 months ago

https://github.com/pzmosquito/eslint-import-resolver-vite/commit/fbeea43791ad41cb7a53d47ae8ef4b5bec735d4c works for me