It throws an error which says 'path' should be listed in the project's dependencies. Run 'npm i -S path' to add it.
The eslintrc contains environment configuration:
"env": {
"browser": true,
"es6": true,
"node": true,
"jest": true
},
It does not throw this error with eslint 5.x.x only with 6.x.x
I wonder if perhaps eslint 6 handles path differently with the node env?
Either way we should use the resolve module鈥檚 isCore method for this.
i catch similar bug
Try set packageDir for import/no-extraneous-dependencies rule.
More info in the article
It鈥檚 work for me.
There does appear to have been a change to resolution. With ESLint v6, e.g. path now seems to resolve to path-browserify, rather than the Node built-in.
If so that鈥檚 a major bug; can you provide a minimal repro?
Also can you confirm if eslint is depending on resolve, and if so, can you try downgrading it to v1.11.0?
I don't think it's resolve or require.resolve. I think it's something specific to the webpack resolver now.
If I log the inputs to isBuiltIn in: https://github.com/benmosher/eslint-plugin-import/blob/65121104ea4659f81e8cb07184b7c1ee346a4a6f/src/core/importType.js#L25
I see e.g.
path {
'import/resolver': { webpack: { config: [Object] }, node: { extensions: [Array] } },
react: { pragma: 'React', version: '16.0' },
propWrapperFunctions: [ 'forbidExtraProps', 'exact', 'Object.freeze' ],
'import/extensions': [ '.js', '.mjs', '.jsx' ],
'import/core-modules': [],
'import/ignore': [ 'node_modules', '\\.(coffee|scss|css|less|hbs|svg|json)$' ]
} /Users/jjia/vendor/react-bootstrap/node_modules/path-browserify/index.js
I believe this issue comes from eslint-module-utils/resolve.
I mean, it makes perfect sense to me that the webpack resolver maps core modules to their respective browser shims - but i don鈥檛 know why eslint 6 would change that.
I'm seeing the same issue after upgrading to eslint v6.
I can't explain _why_ it works, but try adding this to your eslint config:
{
...
settings: {
'import/resolver': {
node: {},
},
}
}
Adding onto @kelchm 's solution, node had to be the first resolver for my eslint to work.
...
settings: {
'import/resolver': {
node: {}, // placed above other resolver configs
webpack: { ... }
}
}
}
The above worked for me as well. We had a repo where most files ran through webpack, but a few were Node configs. Overriding those to use the node resolver fixed the issues.
As such, I don't think there was a bug here.
The eslint-import-resolver-node package would need to be installed to devDependencies in your project's package.json in order to set the node property, right?
Correct.
If I revert back from [email protected] to @5.16.0, while leaving [email protected] then the problem goes away. Making the change https://github.com/benmosher/eslint-plugin-import/issues/1396#issuecomment-509384041 with [email protected] also makes the problem go away.
Adding onto @kelchm 's solution,
nodehad to be the first resolver for my eslint to work.... settings: { 'import/resolver': { node: {}, // placed above other resolver configs webpack: { ... } } } }
Does any one know why this works? 馃
It may be that the import/resolver setting implicitly depends on the order in which the object was defined; since object keys are conceptually unordered, and only became ordered in the spec in ES2015, it'd probably be better for this to be an array if order matters.
eslint-import-resolver-node
doesnt seem to work
https://github.com/benmosher/eslint-plugin-import/issues/1396#issuecomment-511007063 is the proper solution.
Please file a new issue if you're still having trouble with the latest release.
Most helpful comment
Adding onto @kelchm 's solution,
nodehad to be the first resolver for my eslint to work.