Angular-cli: TypeError: core.resolve is not a function

Angular-cli: TypeError: core.resolve is not a function

我有一个预先开发的 angular 项目,我只是 运行 npm i 在本地安装它的包,然后 ng serve 到 运行 项目,该项目运行良好,没有问题 但是 ..

当我想用 ng g c new-component 创建一个新组件时,我得到了这个错误:

core.resolve is not a function
TypeError: core.resolve is not a function
    at NodeModulesEngineHost._resolvePackageJson (C:\myProject\node_modules\@angular-devkit\schematics\tools\node-module-engine-host.js:22:21)
    at NodeModulesEngineHost._resolveCollectionPath (C:\myProject\node_modules\@angular-devkit\schematics\tools\node-module-engine-host.js:43:36)
    at NodeModulesEngineHost.createCollectionDescription (C:\myProject\node_modules\@angular-devkit\schematics\tools\file-system-engine-host-base.js:105:27)
    at SchematicEngine._createCollectionDescription (C:\myProject\node_modules\@angular-devkit\schematics\src\engine\engine.js:70:40)
    at SchematicEngine.createCollection (C:\myProject\node_modules\@angular-devkit\schematics\src\engine\engine.js:63:43)
    at Object.getCollection (C:\..myProject\node_modules\@angular\cli\utilities\schematics.js:39:31)
    at Class.run (C:\myProject\node_modules\@angular\cli\tasks\schematic-get-options.js:11:41)
    at Class.beforeRun (C:\myProject\node_modules\@angular\cli\commands\generate.js:101:31)
    at C:\..myProject\node_modules\@angular\cli\ember-cli\lib\cli\cli.js:138:24

我删除了 node_modules 文件夹,然后重新 运行 npm i,仍然是同样的问题。

我也在网上搜索过,没有找到任何关于这个问题的资源。

这是我的本地配置 ng version:

   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
    
Angular CLI: 1.7.4
Node: 14.17.5
OS: win32 x64
Angular: 5.2.11
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cdk: 5.2.5
@angular/cli: 1.7.4
@angular/material: 9.2.4
@angular-devkit/architect: 0.1102.17
@angular-devkit/build-angular: 0.1102.17
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/build-webpack: 0.1102.17
@angular-devkit/core: 11.2.17
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.5.3
webpack: 3.11.0

package.json

{
..
..
"dependencies": {
    "2": "^3.0.0",
    "@agm/core": "1.0.0-beta.3",
    "@agm/snazzy-info-window": "^1.0.0-beta.7",
    "@akveo/ng2-completer": "^9.0.1",
    "@angular/animations": "^5.2.0",
    "@angular/cdk": "^5.2.5",
    "@angular/common": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.0",
    "@angular/forms": "^5.2.0",
    "@angular/http": "^5.2.0",
    "@angular/material": "^9.2.4",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/router": "^5.2.0",
    "@clampy-js/clampy": "^1.0.10",
    "@ngrx/store": "^5.2.0",
    "@ngx-translate/core": "^9.1.1",
    "@ngx-translate/http-loader": "^6.0.0",
    "@ngxs/store": "^2.0.0",
    "@syncfusion/ej2-angular-calendars": "^19.2.62",
    "@syncfusion/ej2-angular-schedule": "^19.2.56",
    "@tinymce/tinymce-angular": "^4.2.0",
    "anchorme": "^2.1.2",
    "angular-2-dropdown-multiselect": "^1.8.0",
    "angular-bootstrap-md": "^5.2.3",
    "angular-star-rating": "^4.0.0-beta.3",
    "angular-svg-icon": "^5.1.1",
    "angular-text-input-highlight": "^1.4.0",
    "angular-tree-component": "^8.5.6",
    "angular2-multiselect-dropdown": "^3.2.1",
    "angular5-csv": "^0.2.10",
    "angular5-data-table": "^1.0.3",
    "angular5-toaster": "^1.0.2",
    "auth0-js": "^9.16.2",
    "chart.js": "^2.7.2",
    "chartjs-plugin-datalabels": "^0.7.0",
    "classlist.js": "^1.1.20150312",
    "cldr-data": "^36.0.0",
    "copy-webpack-plugin": "^4.4.1",
    "core-js": "^2.4.1",
    "css-star-rating": "^1.2.4",
    "element-resize-detector": "^1.2.1",
    "file-saver": "^2.0.5",
    "font-awesome": "^4.7.0",
    "french-badwords-list": "^1.0.5",
    "google-profanity-words": "^1.0.0",
    "hammerjs": "^2.0.8",
    "lodash": "4.17.21",
    "lodash-es": "4.17.21",
    "moment": "^2.29.1",
    "moment-timezone": "0.5.23",
    "mydatepicker": "^2.6.3",
    "ng-intercom": "^7.0.0-beta.1",
    "ng-multiselect-dropdown": "^0.3.4",
    "ng-recaptcha": "^3.0.5",
    "ng2-archwizard": "^2.1.0",
    "ng2-carouselamos": "^3.2.0",
    "ng2-ckeditor": "1.1.9",
    "ng2-completer": "^3.0.3",
    "ng2-select2": "^1.0.0-beta.16",
    "ng2-slim-loading-bar": "^4.0.0",
    "ng2-smart-table": "^1.7.2",
    "ng2-tel-input": "^1.0.16",
    "ng2-tooltip-directive": "^2.1.5",
    "ng4-geoautocomplete": "^0.1.0",
    "ng5-masonry": "^1.0.7",
    "ng5-validation": "^1.0.0",
    "ngx-bootstrap": "^2.0.5",
    "ngx-color-picker": "^8.1.0",
    "ngx-contextmenu": "^4.2.0",
    "ngx-drag-drop": "^2.0.0",
    "ngx-file-drop": "2.0.5",
    "ngx-image-cropper": "^1.4.1",
    "ngx-infinite-scroll": "^0.8.3",
    "ngx-lazy-load-images": "^1.3.1",
    "ngx-loading": "^2.0.1",
    "ngx-odinvt-emoji-mart": "0.0.5",
    "ngx-pagination": "^3.2.0",
    "ngx-permissions": "^4.1.0",
    "ngx-quill": "^1.6.0",
    "ngx-slick-carousel": "^0.4.1",
    "ngx-socket-io": "^3.0.1",
    "ngx-spinner": "2.0.0",
    "ngx-textarea-autosize": "^2.0.3",
    "ngx-youtube-player": "^0.1.0",
    "node-sass": "^4.14.1",
    "onesignal": "^0.1.2",
    "primeicons": "^1.0.0",
    "primeng": "^6.1.5",
    "print-js": "^1.6.0",
    "rxjs": "^5.5.6",
    "rxjs-compat": "^6.6.7",
    "slick-carousel": "^1.8.1",
    "snazzy-info-window": "^1.1.1",
    "socket.io-client": "^2.1.1",
    "time-ago-pipe": "^1.3.2",
    "ts-xlsx": "0.0.11",
    "typescript": "~2.5.3",
    "xlsx": "^0.16.6",
    "zone.js": "^0.8.19"
  },
  "devDependencies": {
    "@angular-builders/custom-webpack": "^11.1.1",
    "@angular-eslint/eslint-plugin": "^1.0.0",
    "@angular/cli": "~1.7.4",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@ngxs/devtools-plugin": "^3.6.2",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/lodash": "4.14.50",
    "@types/node": "~6.0.60",
    "@typescript-eslint/eslint-plugin": "^4.12.0",
    "@typescript-eslint/parser": "^4.12.0",
    "agm-overlays": "^1.4.1",
    "codelyzer": "^4.0.1",
    "eslint": "^7.17.0",
    "eslint-config-standard": "^16.0.2",
    "eslint-plugin-import": "^2.22.1",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^4.2.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "prettier": "^2.2.1",
    "protractor": "^5.3.2",
    "systemjs-plugin-json": "^0.3.0",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  }
..
..
}

根据@Batajus 关于兼容性的回复,我可以通过以下步骤解决此问题:

  1. 删除 node_module 文件夹
  2. 删除包-lock.json
  3. 运行 npm i
  4. 最后 npm i -D @angular-devkit/core@0.3.2(angular-devkit/core 对于 Angular V5 应该是 0.3.2)