Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix eslint error when using the node: protocol when importing Node.js builtin modules

Please, direct me what should I write in .eslintrc in my situation.

https://github.com/nodejs/node/issues/38343
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-node-protocol.md

If I deny this rule I got error:

import path from "path"; // ESLint: Prefer `node:path` over `path`.(unicorn/prefer-node-protocol)

Else I got this error:

import path from "node:path"; // ESLint: Unable to resolve path to module 'node:path'.(import/no-unresolved)

I want to use both of rules. But I can't imagine what to write down for linter to understand that node:path is just about the same as path. Node environment is enabled for this file:

"env": {
  "node": true
}

node -v -> v14.16.1

like image 462
Nick_Rimer Avatar asked Nov 07 '22 02:11

Nick_Rimer


1 Answers

Currently you need node 16 to use the "node:" prefix.

Support will be backported to node 14 and 12 but (at the time of writing this) these backports haven't been released yet.

Node 14.18.0 should include the backport (looking at this commit).

like image 165
Rebecca Stevens Avatar answered Nov 11 '22 03:11

Rebecca Stevens