【问题标题】:Failed to update angular 11 project to angular 12无法将 Angular 11 项目更新为 Angular 12
【发布时间】:2021-10-16 22:26:57
【问题描述】:

我正在尝试更新使用 Angular 11 版本开发的项目。现在我想将版本更新到 12。所以我运行了命令 ng update @angular/core@12 @angular/cli@12。但是每次出现以下错误。

E:\Workspace\My Projects\CashFlow-Web>ng update @angular/core@12 @angular/cli@12 安装的本地 Angular CLI 版本低于 最新的稳定版本。安装临时版本来执行 更新。 √ 包安装成功。 内部/模块/cjs/loader.js:888 抛出错误; ^

错误:找不到模块 'E:\Workspace\My Projects\CashFlow-Web'C:\Users\Nasir\AppData\Local\Temp\angular-cli-packages-kgrL8I\node_modules@angular\cli\bin\ng'' 在 Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15) 在 Function.Module._load (internal/modules/cjs/loader.js:730:27) 在 Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) 在 internal/main/run_main_module.js:17:47 { code: 'MODULE_NOT_FOUND', requireStack: [] }

我确实删除了 package-lock.json 文件和 node_modules 文件夹并运行了 npm install 命令,但仍然出现上述问题当我运行更新命令时。请帮助我找到解决方案。

这是我的 Package.json 文件:

{
  "name": "e-cash",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "generateData": "node server/generateData.js > server/database.json",
    "server": "json-server --watch server/database.json"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^11.2.14",
    "@angular/cdk": "^12.0.4",
    "@angular/common": "~11.2.9",
    "@angular/compiler": "~11.2.9",
    "@angular/core": "~11.2.9",
    "@angular/forms": "~11.2.9",
    "@angular/localize": "^11.2.9",
    "@angular/platform-browser": "~11.2.9",
    "@angular/platform-browser-dynamic": "~11.2.9",
    "@angular/router": "~11.2.9",
    "@ng-bootstrap/ng-bootstrap": "^8.0.0",
    "angular-ng-stepper": "^1.0.6",
    "angular2-multiselect-dropdown": "^4.6.10",
    "bootstrap": "^4.5.0",
    "faker": "^5.1.0",
    "google-libphonenumber": "^3.2.21",
    "intl-tel-input": "^17.0.13",
    "json-server": "^0.16.3",
    "moment": "^2.29.1",
    "ng-month-picker": "^1.1.5",
    "ng-multiselect-dropdown": "^0.3.4",
    "ngx-bootstrap": "^6.2.0",
    "ngx-currency": "^2.5.2",
    "ngx-image-cropper": "^3.3.5",
    "ngx-intl-tel-input": "^3.1.1",
    "ngx-perfect-scrollbar": "^10.1.0",
    "ngx-spinner": "^11.0.1",
    "ngx-toastr": "^14.0.0",
    "rxjs": "~6.6.0",
    "tslib": "^2.0.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1102.8",
    "@angular/cli": "~11.2.8",
    "@angular/compiler-cli": "~11.2.9",
    "@types/node": "^12.11.1",
    "@types/jasmine": "~3.6.0",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^6.0.0",
    "jasmine-core": "~3.6.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~6.3.2",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~4.0.2"
  }
}

angular.json 文件

 {
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "e-Cash": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/e-Cash",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "node_modules/bootstrap/dist/css/bootstrap.min.css",
              "node_modules/angular2-multiselect-dropdown/themes/default.theme.css",
              "node_modules/ngx-toastr/toastr.css",
              "node_modules/intl-tel-input/build/css/intlTelInput.css",
              "src/styles.css"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "e-Cash:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "e-Cash:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "e-Cash:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "e-Cash:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "e-Cash:serve:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "e-Cash",
  "cli": {
    "analytics": "573cd480-259c-4d50-b647-d0a80a34b23a"
  }
}

【问题讨论】:

  • 看起来好像你的模块中有一个奇怪的引用。也许你有类似import { something } from 'ng'; 的东西。或者您引用了已删除的内部控制模块。真的,这是一个检查你的文件并找到有问题的模块引用的问题。
  • 您使用的是 Typescript 4.2 + 吗?你的 Node.js 版本是 11+ 吗?
  • 我使用的是 typescript 4.2 而 NodeJs 是 14.17.0
  • 更新时使用--force
  • 使用 --force 命令不起作用

标签: angular angular-cli angular-upgrade


【解决方案1】:

你需要安装依赖项

npm 安装

【讨论】:

  • 如果您有新问题,请点击 按钮提出问题。如果有助于提供上下文,请包含指向此问题的链接。 - From Review
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-23
  • 2022-06-11
  • 1970-01-01
  • 2021-08-08
  • 2020-02-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多