question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Next.js app with absolute path - getting eslint "Unable to resolve path to module" error

See original GitHub issue

Hello, I’m wondering what I’ve done wrong because in a really simple use case i’m still getting the “Unable to resolve path to module” error. Here is my configuration: "eslint-plugin-import": "^2.23.3", "eslint-import-resolver-alias": "^1.1.2",

My folders: project/src/components project/src/styles project/src/utils

project/jsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@components/*": [
        "src/components/*"
      ],
      "@utils/*": [
        "src/utils/*"
      ],
      "@styles/*": [
        "src/styles/*"
      ]
    }
  }
}

project/.eslintrc.js

settings: {
  'import/resolver': {
    alias: [
      ['@components', './src/components'],
      ['@styles', './src/styles'],
      ['@utils', './src/utils'],
    ],
  },
},

I’m using the import like this import Layout from '@components/Layout'; The Next.js compilation is working great but eslint doesn’t seems to use import/resolver settings. Any ideas? Thanks.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
ravenbasixcommented, Jun 2, 2021

I tried creating a repo which replicates the issue and found why it wasn’t working. If you are extending eslint configuration with the extends option, you need to add plugin:import/resolver in the list.

.eslintrc.js

module.exports = {
  extends: [
    ...
    'plugin:import/resolver',
  ],
};

Thank you for your help @PsyGik.

0reactions
mildrenbencommented, Jun 7, 2022

Thanks @ravenbasix This should be added to the wiki!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using eslint with typescript - Unable to resolve path to module
As soon as I compile the .ts file to a .js, the error goes away. However, since eslint is supposed to work with...
Read more >
ESLint: Unable to resolve path to module #1180 - GitHub
We have solution for absolute path, like this: import MyComponent from 'src/components/MyComponent' It is work fine for yarn start, ...
Read more >
Unable to resolve path to module 'next/app'.eslint : r/nextjs
Unable to resolve path to module 'next/app'.eslint. &. Resolve error: ENOENT: no such file or directory, stat './tsconfig.json'. Any ideas why?
Read more >
ESLint Unable to resolve path to module
Error Message: (ESLint) import/no-unresolved Unable to resolve path to module '@project/components/ThemeProviders' Active.
Read more >
"Unable to resolve path to module" while the path exist-Reactjs
Coding example for the question Sublime eslint plugin: "Unable to resolve path to module" while the path exist-Reactjs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found