小编kam*_*aes的帖子

错误 [ERR_REQUIRE_ESM] - Husky、lint-staged、eslint - nodeJS:

尽管还有其他问题,但大多数都没有得到答复,或者给出的答复对我不起作用。

对于它给出的显然 eslint 正在 node_modules 中查找的内容,这里是给定的错误:

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/kamoraes/Workspace/node_adc/node_modules/supports-color/index.js from /home/kamoraes/Workspace/node_adc/.git/hooks/commit-msg not supported.
Instead change the require of index.js in /home/kamoraes/Workspace/node_adc/.git/hooks/commit-msg to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/home/kamoraes/Workspace/node_adc/.git/hooks/commit-msg:8:23) {
  code: 'ERR_REQUIRE_ESM'
}


Node v16.13.0
Run Code Online (Sandbox Code Playgroud)

问题是,该项目正处于第一步,快速在同一节点和纱线、版本上的另一台机器上重做该项目,不会给出相同的错误。还请我的一个朋友尝试一下。没有给出错误。

另外,这个项目是一门课程,执行相同的步骤,这是我现在的完整代码:

https://github.com/kaiqueAMoraes/clean-node-api

此给定错误的最后一次提交是杂务:eslintignore 6250e5bdea05cc2eb413c8a57a97e4bbe4bd5bb9

我添加了哈士奇,lint-staged

yarn add -D husky lint-staged
Run Code Online (Sandbox Code Playgroud)

然后添加它们各自的配置文件

.huskyrc.json:

{
  "hooks": {
    "pre-commit": "lint-staged"
  }
}
Run Code Online (Sandbox Code Playgroud)

.lintstagedrd.json:

{
  "*.ts": [
    "eslint 'src/**' --fix",
    "git add"
  ]
}

Run Code Online (Sandbox Code Playgroud)

供参考:tsconfig:

{
  "compilerOptions": …
Run Code Online (Sandbox Code Playgroud)

node.js eslint husky eslintrc

5
推荐指数
1
解决办法
2044
查看次数

标签 统计

eslint ×1

eslintrc ×1

husky ×1

node.js ×1