未找到角度测试模块:错误:无法解决

时间:2018-05-09 07:09:34

标签: angular

我上周使用命令ng new [myProjectName]启动了这个Angular项目。我使用ng g c [componentName]生成了组件,它们使用.spec.ts文件正确生成了每个组件。然后,在实现业务逻辑并编写一些测试代码之后,请说ng test以尝试运行测试代码,但是会得到一大堆错误。

我在命令行上遇到的所有这些错误都采用以下形式:Module not found : Error : can't resolve [someNodeJSDependency] in [someNodeJSLibFolder]。应该生成的浏览器(应该包含测试的输出)无法捕获(它启动两到三次,但是空白,然后关闭)。然后说它放弃了。

错误的屏幕截图:

enter image description here enter image description here

项目的package.json如下所示:

{
  "name": "open-source-roads-page",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "core-js": "^2.4.1",
    "rxjs": "^5.5.2",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "^1.5.5",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.4.2"
  }
}

我尝试在项目根目录中说node rebuild,但这对这些错误没有任何影响。

1 个答案:

答案 0 :(得分:0)

我删除了node_modules文件夹并重新安装了最新版本的node.js后,我得到了同样的错误,这对我有用。