从Angular9迁移到Angular13时,ESLint的构建遇到了困难

由于从Angular9升级到了Angular13,我也将代码检查工具从TSLint迁移到了ESLint,但是当我运行ng lint时,它会报错让我感到很困扰。

問題發生的地點和應對措施

首次出现错误的原因是下面的错误信息。

An unhandled exception occurred: Failed to load parser '@angular-eslint/template-parser' declared in

这意味着如果在eslintrc.json中没有parser的设置,就需要在eslintrc.json中添加以下内容。

{
  "files": ["*.component.html"],
  "parser": "@angular-eslint/template-parser",
  "parserOptions": {
    "project": "./tsconfig.app.json",
    "ecmaVersion": 2020,
    "sourceType": "module"
  },
  "rules": {},
  "plugins": ["@angular-eslint/template"]
}

暫時先延後細節設定,先試著運行ng lint,但還是出現同樣的錯誤…
我想可能是編譯或其他地方有問題,於是先檢查了一下package.json。

"@angular-devkit/build-angular": "^13.3.9",
"@angular-eslint/builder": "1.2.0",
"@angular-eslint/eslint-plugin": "1.2.0",
"@angular-eslint/eslint-plugin-template": "1.2.0",
"@angular-eslint/schematics": "^14.0.2",
"@angular-eslint/template-parser": "1.2.0",
"@angular/cli": "~13.3.9",

当我尝试更新@angular-eslint/builder到1.2.0版本时,似乎存在问题。

ERR! stack Error: Can't find Python executable "python",(詳細はコピペミスりました)

添加下述内容到Dockerfile时,我开始怀疑是否需要使用Python?

RUN apk add py3-pip make g++

终于完成了这么多工作,现在更新也正常运行。

CC(target) Release/obj.target/nothing/../../node-addon-api/nothing.o
  AR(target) Release/obj.target/../../node-addon-api/nothing.a
  COPY Release/nothing.a
  CXX(target) Release/obj.target/watcher/src/binding.o
  CXX(target) Release/obj.target/watcher/src/Watcher.o
  CXX(target) Release/obj.target/watcher/src/Backend.o
  CXX(target) Release/obj.target/watcher/src/DirTree.o
  CXX(target) Release/obj.target/watcher/src/watchman/BSER.o
  CXX(target) Release/obj.target/watcher/src/watchman/WatchmanBackend.o
  CXX(target) Release/obj.target/watcher/src/shared/BruteForceBackend.o
  CXX(target) Release/obj.target/watcher/src/linux/InotifyBackend.o
  CXX(target) Release/obj.target/watcher/src/unix/legacy.o
  SOLINK_MODULE(target) Release/obj.target/watcher.node
  COPY Release/watcher.node

package.json看起来不错

 "devDependencies": {
    "@angular-devkit/build-angular": "^13.3.9",
    "@angular-eslint/builder": "13.5.0",
    "@angular-eslint/eslint-plugin": "13.5.0",
    "@angular-eslint/eslint-plugin-template": "13.5.0",
    "@angular-eslint/schematics": "^14.0.2",
    "@angular-eslint/template-parser": "13.5.0",
    "@angular/cli": "~13.3.9",

我只对@angular-eslint/schematics的14有点疑虑,但暂且不管它吧。因为我打算将Angular本身升级到14版本…

最后

总之,为了不忘记,我写下了很多东西,如果难以阅读的话,请原谅。
另外,我想留下的部分是在解决问题之后,所以写了许多东西…
以后我会在经历中保留下来,并且对此进行反省。

如果有任何错误,请务必指出。
广告
将在 10 秒后关闭
bannerAds