我收集了一些代码,我必须编写一些unint / e2e测试。我唯一的问题是我在运行ng测试时,收到此错误:
Chrome 67.0.3396 (Windows 10 0.0.0) ERROR
{
"message": "Uncaught ReferenceError: System is not defined\nat http://localhost:9876/_karma_webpack_/scripts.bundle.js:1:1\n\nReferenceError: System is not defined\n at http://localhost:9876/_karma_webpack_/scripts.bundle.js:1:1",
"str": "Uncaught ReferenceError: System is not defined\nat http://localhost:9876/_karma_webpack_/scripts.bundle.js:1:1\n\nReferenceError: System is not defined\n at http://localhost:9876/_karma_webpack_/scripts.bundle.js:1:1"
}
Chrome 67.0.3396 (Windows 10 0.0.0) ERROR
{
"message": "Uncaught ReferenceError: System is not defined\nat http://localhost:9876/_karma_webpack_/scripts.bundle.js:1:1\n\nReferenceError: System is not defined\n at http://localhost:9876/_karma_webpack_/scripts.bundle.js:1:1",
"str": "Uncaught ReferenceError: System is not defined\nat http://localhost:9876/_karma_webpack_/scripts.bundle.js:1:1\n\nReferenceError: System is not defined\n at http://localhost:9876/_karma_webpack_/scripts.bundle.js:1:1"
}
我觉得它与angular.json文件以及tsconf.spec文件有关。我尝试了很多可能的解决方案,我在网上找到但总是发现同样的错误。这是我的tsconf.spec和angular.josn。谢谢。
configspec:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/spec",
"baseUrl": "./",
"module": "commonjs",
"types": [
"jasmine",
"node"
]
},
"files": [
"test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}
Angular.json
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": ""
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.css"
],
"scripts": []
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json",
"exclude": "**/node_modules/**"
},
{
"project": "src/tsconfig.spec.json",
"exclude": "**/node_modules/**"
},
{
"project": "e2e/tsconfig.e2e.json",
"exclude": "**/node_modules/**"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"component": {}
}
}
我目前正在使用角度6,我已经回到4但仍然收到相同的错误。
编辑:解决了这个问题,但这是一个奇怪的解决方案。在我的angular.json文件中有一个导致此错误的脚本。我只是删除了脚本,一切都很好。