简体   繁体   English

使用节点时如何修复 eslint 错误:导入 Node.js 内置模块时的协议

[英]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.请指导我在我的情况下应该在.eslintrc中写什么。

https://github.com/nodejs/node/issues/38343 https://github.com/nodejs/node/issues/38343
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-node-protocol.md 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 .但我无法想象要为 linter 写下什么来理解node:pathpath几乎相同。 Node environment is enabled for this file:为此文件启用了节点环境:

"env": {
  "node": true
}

node -v -> v14.16.1

Currently you need node 16 to use the "node:" prefix.目前,您需要节点 16 才能使用“node:”前缀。

Support will be backported to node 14 and 12 but (at the time of writing this) these backports haven't been released yet.支持将向后移植到节点 14 和 12,但(在撰写本文时)这些向后移植尚未发布。

Node 14.18.0 should include the backport ( looking at this commit ).节点 14.18.0 应该包括反向端口( 查看此提交)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM