gpt4 book ai didi

Angular ng 测试模块未找到 : Error: can't resolve

转载 作者:行者123 更新时间:2023-12-05 07:34:17 26 4
gpt4 key购买 nike

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

我在命令行上遇到的所有这些错误都采用以下形式:找不到模块:错误:无法解析 [someNodeJSLibFolder] 中的 [someNodeJSDependency]。应该产生的浏览器,应该包含测试的输出,无法捕获(它启动两到三次,但空白,然后关闭)。 ng 然后说它正在放弃。

错误截图:

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,但这对这些错误没有任何影响。

最佳答案

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

关于 Angular ng 测试模块未找到 : Error: can't resolve,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50247460/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com