kam*_*aes 5 node.js eslint husky eslintrc
尽管还有其他问题,但大多数都没有得到答复,或者给出的答复对我不起作用。
对于它给出的显然 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)
问题是,该项目正处于第一步,快速在同一节点和纱线、版本上的另一台机器上重做该项目,不会给出相同的错误。还请我的一个朋友尝试一下。没有给出错误。
另外,这个项目是一门课程,执行相同的步骤,这是我现在的完整代码:
此给定错误的最后一次提交是杂务: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": {
"outDir" : "./dist",
"module": "commonjs",
"target": "es2019",
"strictNullChecks": true,
"esModuleInterop": true,
"allowJs": true
}
}
Run Code Online (Sandbox Code Playgroud)
eslintrc:
{
"extends": "standard-with-typescript",
"parserOptions": {
"project": "./tsconfig.json"
}
}
Run Code Online (Sandbox Code Playgroud)
gitignore 和 eslintignore 都会忽略 node_modules 和 dist
归档时间: |
|
查看次数: |
2044 次 |
最近记录: |