Unable to resolve path to module 'nanoid' since Webpack 5
See original GitHub issueHi ✋
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:
- Created 3 years ago
- Reactions:2
- Comments:12 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You’re missing the node resolver. Add
"node": {}
before “webpack”.@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.