Closed clshortfuse closed 3 years ago
Realized path/posix
doesn't work with ES6. That's another issue entirely.
path/posix is a core module as of node 15.3 and this plugin will recognize it as such on the appropriate node version.
On node 15.8.0 and receiving an error
Unable to resolve path to module 'fs/promises'. eslint import/no-unresolved
@nathanhannig if you're using the latest version of eslint-plugin-import (and of resolve
or is-core-module
, which it depends on) it will work fine.
@ljharb I am using "eslint-plugin-import": "2.22.1",
and still get this:
The dependents I have:
"resolve": {
"version": "1.19.0",
"is-core-module": {
"version": "2.2.0",
Suppose I am not using the latest of the dependencies and that is why it does not work.
@thernstig what version of node are you using? fs/promises
is only a core module in node v14+.
~/code/projectA (PROMISESCOOL)> node --version
v14.15.1
I've also set this in my package.json
:
"engines": {
"node": "14.15.1"
},
Can you share your eslint config? You need to be using the node
resolver to resolve node core modules.
Scaled it down to an example that still gives the error:
{
"root": true,
"parserOptions": {
"ecmaVersion": 2020
},
"env": {
"node": true,
"es2020": true,
"jest": true
},
"extends": [
"airbnb-base",
"plugin:node/recommended",
"plugin:jest/recommended",
"plugin:jest/style",
"plugin:jsdoc/recommended",
"prettier"
],
"rules": {
"node/exports-style": ["error", "module.exports"],
"node/prefer-promises/dns": "error"
}
}
@thernstig and you're getting that error on the CLI as well, or only in your editor?
CLI as well.
Could it be that I have to update these?
"resolve": {
"version": "1.19.0",
"is-core-module": {
"version": "2.2.0",
No, those are late enough that it should work properly.
can you run eslint with the show config option, to print out the fully flattened config being used for the file being warned?
@ljharb Here you go:
@thernstig thanks; with that exact setup, on node v14.15.1, i'm unable to reproduce your issue. i only get 1:7 error 'fsp' is assigned a value but never used no-unused-vars
.
To confirm, you're seeing this error in a real terminal, not in vscode's fake terminal?
@ljharb I am getting it both in the terminal running eslint
as well as in VS Code. Let me try to track down what the real fault is then.
@ljharb first of all, I want to say that I apologize for wasting your time with thinking this also happened in the CLI. It does not. I did not look at the correct package in package-lock.json when saying I had the right version of `"resolve"´. Normally a mistake I do not do, and feel bad for wasting your precious time.
With that said, it does work now, except in VS Code (restarted it and all). Is that known?
vscode has its own version of node built in, and it might not be v14 - I’m not entirely sure, but I’d expect you can configure it to use your local version, and then eslint should work the same.
Hm, the built-in version should not be related to what ESLint reports there. It should use the one we have in the environment. But I will investigate further and let this thread die. At least eslint-plugin-import works :)
eslint can't know what node versions are in your environment, it only knows what it's being ran with.
I submitted an issue on the VS Code ESLint plugin to ask about this, because e.g. in Python, the linters can know via the environment what version of Python is used. Albeit that is Python and not Node.js.
right - the version of node it's using is what it knows.
For anyone that finds this still. VSCode still ships with v12 Node where fs/promises is not available.
You can solve this by adding the following VSCode setting, to use your system node.
{
"eslint.runtime": "node"
}
And for even more info, that config above cannot be used in your User config (only remote config or workspace config). For this discussion check https://github.com/microsoft/vscode-eslint/issues/1188, which then lead to me creating a VS Code issue, see https://github.com/microsoft/vscode/issues/119183. If they fix that one, you will be able to set the above in your User settings as well.
Trying to use import modules that specify a subpath aren't supported and I haven't been able to find a way to work around it.
Error:
Example:
I tried the following with this plugin to no avail:
Similarly, this problem exists with
node/no-missing-import
but I can use the following workaround: