node.js - 错误 [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
问题是,该项目处于第一步,在同一节点和纱线,版本的另一台机器上快速重做项目,不要给出相同的错误。还请了我的一个朋友试试。没有给出错误。
另外,这个项目是一门课程,步骤相同,这是我现在的整个代码:
这个给定错误的最后一次提交是苦差事:eslintignore 6250e5bdea05cc2eb413c8a57a97e4bbe4bd5bb9
我已经添加了哈士奇,lint-staged
yarn add -D husky lint-staged
然后添加他们各自的配置文件
.huskyrc.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 和 eslintignore 都忽略 node_modules 和 dist
解决方案
推荐阅读
- django - 更改 docker 映像会引发:psycopg2.errors.UndefinedFile: could not access file "$libdir/postgis-3" 错误
- react-native - 设置 react-native-geolocation-service
- r - 基于一行的患者数据,对该患者的其他行进行子集化
- typescript - 为什么此 CustomExtract 返回与默认提取不同的结果?
- python - Mercurial合并工具INI列表可以清除吗?(避免“找不到合并工具”垃圾邮件。)
- javascript - 测试从另一个函数返回的函数类型
- python - 没有 NaN 值的行中字符和单词的平均值
- java - Mybatis Batch 将 Java BigDecimal 插入 SQL Server decimal(18,2) 无法正常工作
- unit-testing - 超时 - 使用 jest.useFakeTimers('modern') 和 jest.setSystemTime() 时未调用异步回调
- python - 没有卡夫卡连接器的卡夫卡到 postgres