Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import/no-unresolved error with 'node:' URLs (Node.js ESM) #2372

Closed
cdauth opened this issue Jan 25, 2022 · 5 comments
Closed

import/no-unresolved error with 'node:' URLs (Node.js ESM) #2372

cdauth opened this issue Jan 25, 2022 · 5 comments

Comments

@cdauth
Copy link

cdauth commented Jan 25, 2022

ECMAScript modules in Node.js support importing Node.js builtin modules using node: URLs (see the documentation), for example:

import fs from 'node:fs/promises';

Using such URLs causes eslint-plugin-import to raise an import/no-unresolved error.

@ljharb
Copy link
Member

ljharb commented Jan 25, 2022

What version of node are you using?

If you're seeing this error in your editor, then what version of node is your editor using?

a) this plugin does not explicitly support native ESM, it expects transpiled ESM, which means that import is really require
b) node:fs/promise is only a core module for require in node ^14.18 || >= 16.

@cdauth
Copy link
Author

cdauth commented Jan 25, 2022

I'm using Node.js v17.3.0. I'm assuming my editor (Code - OSS) is using the same.

I tested it and it actually seems that the error only shows up in the editor, but not when I run eslint from the command-line.

I didn't know that this plugin does not support native ESM. I'm using @typescript-eslint/parser, although I see the error both with TypeScript and with JavaScript files. In my tsconfig.json I have "module": "esnext" set, but maybe @typescript-eslint/parser ignores that and transpiles it to require anyways.

Maybe my eslint editor plugin is somehow misconfigured, although I don't know what setting it could be.

@ljharb
Copy link
Member

ljharb commented Jan 25, 2022

vscode has an embedded node, which i believe is v12.

The command line is the source of truth, so it's a problem you'll have to fix in your editor.

TS also isn't native ESM, it's a transpiler (which is better than native anyways).

@burtek
Copy link

burtek commented Jan 29, 2022

Just found out, in vscode one can set "eslint.runtime" setting to "node" to force eslint execution in locally installed version of node (see explanation for this option here). Requires full restart of vscode.

image

@ljharb
Copy link
Member

ljharb commented Jan 29, 2022

Duplicate of #2035. Duplicate of #2248.

@ljharb ljharb closed this as completed Jan 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants