错误[ERR_REQUIRE_ESM]-Husky,lint暂存,nodeJS:



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

它给出的esint显然是在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

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

此外,这个项目是一门课程,采取了相同的步骤,这是我目前的全部代码:

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

此给定错误的最后一次提交是家务:eslinignore6250e5bdea05cc2eb413c8a57a97e4bbe4bd5bb9

我添加了哈士奇,皮棉阶段

yarn add -D husky lint-staged

然后添加各自的配置文件

.hustyrc.json:

{
"hooks": {
"pre-commit": "lint-staged"
}
}

.lintstagedrd.json:

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

供参考:tsconfig:

{
"compilerOptions": {
"outDir" : "./dist",
"module": "commonjs",
"target": "es2019",
"strictNullChecks": true,
"esModuleInterop": true,
"allowJs": true
}
}

eslintrc:

{
"extends": "standard-with-typescript",
"parserOptions": {
"project": "./tsconfig.json"
}
}

gitignore和eslintinore都忽略node_modules和dist

遇到了同样的问题。您可以使用git commit -m "your message here" --no-verify绕过检查。

最新更新