johvin / eslint-import-resolver-alias

a simple Node behavior import resolution plugin for eslint-plugin-import, supporting module alias
MIT License
180 stars 10 forks source link

Next.js resolve alias with root/wildcard path? #25

Open dasveloper opened 1 year ago

dasveloper commented 1 year ago

I'm using Next.js and trying to setup aliases in my eslint.

My folder structure is:

/components/Cart.js
/pages/Home.js
/utils/addToCart.js
etc.

and I import them like: import addToCart from '@/utils/addToCart'

Currently I have my eslint import resolver setup like this:

"settings": {
  "import/resolver": {
    "alias": [
        ["@/components", "./components"],
        ["@/utils", "./utils"],
        ["@/pages", "./pages"]
    ]
  }
}

This works great, but I'd like to not have to create each alias individually. Instead, I'd prefer to set up a sort of root alias or wildcard alias like this:

["@/*", "./*"]
or ["@/$", "./$"]
or ["@/", "./"]
etc.

But everything I've tried has broken the imports and given me the "Unable to resolve path to module" error. Is there a correct way to handle this?

maevic commented 1 year ago

Have you tried ["@/*", "./"]? This worked for me.

danny-palma commented 2 months ago

i tried, but not works :(