首页 > 解决方案 > 编译时无法解析应用程序的模块/无法解析模块@angular/core

问题描述

我正在尝试将 Angular 项目从 Windows 10 迁移到 Ubuntu 18.04.4,但编译失败。我收到 TS2307 和 TS2305 错误,即:

16 import { DepositAccountSearchComponent } from '../../../searchCustomer/src/app/deposit-account-search/deposit-account-search.component';
                                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
projects/basicrelation/src/app/app.module-export.ts:17:45 - error TS2307: Cannot find module '../../../searchCustomer/src/app/search-results-table/search-results-table.component'.

17 import { SearchResultsTableComponent } from '../../../searchCustomer/src/app/search-results-table/search-results-table.component';
                                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
projects/basicrelation/src/app/app.module-export.ts:70:3 - error TS2305: Module '"./services"' has no exported member 'HttpService'.

6 import { SearchfilterComponent } from '../../../../../../searchCustomer/src/app/searchfilter/searchfilter.component';
                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
projects/basicrelation/src/app/components/np/np-basic-relation-representatives/np-basic-relation-representatives.component.ts:7:40 - error TS2307: Cannot find module '../../../../../../searchCustomer/src/app/search-results/search-results.component'.

我的 package.json 和 tsconfig.json 文件:

{
  "name": "my-project",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "compodoc": "compodoc -p tsconfig.compdoc.json",
    "compodoc:serve": "compodoc -s tsconfig.compdoc.json"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~8.2.14",
    "@angular/cdk": "~8.2.3",
    "@angular/common": "~8.2.14",
    "@angular/compiler": "~8.2.14",
    "@angular/core": "^8.2.14",
    "@angular/elements": "^8.2.14",
    "@angular/forms": "~8.2.14",
    "@angular/localize": "^9.1.5",
    "@angular/material": "^8.2.3",
    "@angular/platform-browser": "~8.2.14",
    "@angular/platform-browser-dynamic": "~8.2.14",
    "@angular/router": "~8.2.14",
    "@ng-bootstrap/ng-bootstrap": "^5.1.2",
    "@ng-select/ng-select": "^3.3.0",
    "@ngrx/effects": "^8.5.1",
    "@ngrx/entity": "^8.5.1",
    "@ngrx/schematics": "^8.5.1",
    "@ngrx/store": "^8.5.1",
    "@ngrx/store-devtools": "^8.5.1",
    "@webcomponents/webcomponentsjs": "^2.4.0",
    "bootstrap": "^4.3.1",
    "core-js": "^3.4.1",
    "document-register-element": "^1.7.2",
    "html2canvas": "^1.0.0-rc.5",
    "jquery": "^3.4.1",
    "lodash": "^4.17.15",
    "material-design-icons-iconfont": "^5.0.1",
    "moment": "^2.25.3",
    "ngx-cookie-service": "^2.3.0",
    "ngx-toastr": "^11.3.3",
    "rxjs": "~6.4.0",
    "sjcl": "^1.0.8",
    "underscore": "^1.9.2",
    "uuid": "^3.3.3",
    "xlsx": "^0.15.6",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.803.19",
    "@angular-devkit/build-ng-packagr": "~0.803.19",
    "@angular/cli": "~8.3.19",
    "@angular/compiler-cli": "~8.2.14",
    "@angular/language-service": "~8.2.14",
    "@compodoc/compodoc": "^1.1.11",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.0.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "ng-packagr": "^5.4.0",
    "prettier": "^2.0.5",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tsickle": "^0.37.0",
    "tslib": "^1.10.0",
    "tslint": "~5.15.0",
    "tslint-config-prettier": "^1.18.0",
    "typescript": "~3.5.3"
  }
}

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "typeRoots": [
      "../node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ],
    "paths": {
      "common-lib": [
        "dist/common-lib"
      ],
      "common-lib/*": [
        "dist/common-lib/*"
      ]
    }
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": false,
    "strictInjectionParameters": true
  }
}

我尝试将moduleResolutiontsconfig 文件更改为,classic但随后出现错误: ERROR in Could not resolve module @angular/core 然后我删除了 node_modules 文件夹,清理了 npm 缓存并尝试了npm i @angular/core@8npm i但问题仍然存在。

标签: angularangular8

解决方案


推荐阅读