Skip to content

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

@dasveloper

Description

@dasveloper

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions