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.

Unable to resolve path to module 'nanoid' since Webpack 5

See original GitHub issue

Hi ✋

Since the update of Webpack from v4.44.2 to v5.6.0, I get this error:

error  Unable to resolve path to module 'nanoid'  import/no-unresolved

It’s a very strange bug because it doesn’t happen with all Node modules. For example, here the import/no-unresolved rule throw an error for nanoid but not for bowser 🤔

The minimal reproducible repo: https://github.com/gautierrollin/no-unresolved-false-positive or just:

git clone git@github.com:Gautierrr/no-unresolved-false-positive.git
npm install
npm run lint

You can downgrade the Webpack version to make it work:

npm install webpack@4.44.2 webpack-cli@3.3.12 && npm run lint

My (minimal) eslint config:

module.exports = {
  env : {
    browser : true,
    es2021 : true
  },

  parserOptions : {
    ecmaVersion : 12,
    sourceType : "module"
  },

  plugins : [
    "import"
  ],

  rules : {
    "import/no-unresolved" : ["error"]
  },

  settings : {
    "import/resolver" : "webpack"
  }
};

Ps: my real Webpack config is bigger than the one in the reproducible repo. But it’s just a minimal reproducible repo, I get the same error with resolve.extensions option and others…

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
ljharbcommented, Nov 28, 2020

You’re missing the node resolver. Add "node": {} before “webpack”.

2reactions
ljharbcommented, Dec 2, 2020

@Gautierrr generally you only want the node resolver, unless you have webpack-specific aliases (and in that case, i’d suggest using babel to resolve them instead of webpack). You are right tho that the webpack resolver alone should theoretically be enough (although I’ve never omitted the node resolver in any project before) - however, it’s entirely possible that webpack 5 (or enhanced-require) has broken something that used to work in webpack 4, or, that nanoid’s use of the “exports” field is causing issues.

We use resolve, which does not yet have support for the “exports” field - I suspect once we add that support, that this problem would go away.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to resolve path to module 'nanoid' since Webpack 5
Hi ✋ Since the update of Webpack from v4.44.2 to v5.6.0, I get this error: error Unable to resolve path to module 'nanoid' ......
Read more >
Using eslint with typescript - Unable to resolve path to module
You can set the ESLint module import resolution by adding this snippet to your .eslintrc.json configuration file:
Read more >
Unable to resolve path to module 'nanoid' since Webpack 5
Coming soon: A brand new website interface for an even better experience!
Read more >
Module Resolution - webpack
A resolver is a library which helps in locating a module by its absolute path. A module can be required as a dependency...
Read more >
module-not-found - Next.js
The module you're trying to import is in a different directory. Make sure that the path you're importing refers to the right directory...
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