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

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

Open
dasveloper opened this issue Jan 27, 2023 · 1 comment
Open

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

dasveloper opened this issue Jan 27, 2023 · 1 comment

Comments

@dasveloper
Copy link

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
Copy link

maevic commented Apr 29, 2023

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

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