我使用 Angular (TypeScript)
15.1.0
19.7.0
9.5.1
我使用时出现错误
ng test
:
错误:
⠙ Generating browser application bundles (phase: setup)...node:internal/process/promises:289
triggerUncaughtException(err, true /* fromPromise */);
^
AssertionError [ERR_ASSERTION]: Compilation cannot be undefined.
at webpackOptions.entry (/Users/***/Documents/folder/node_modules/@angular-devkit/build-angular/src/builders/karma/find-tests-plugin.js:70:38) {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: undefined,
expected: true,
operator: '=='
}
我的package.json
{
"name": "epic-trip-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "jasmine"
},
"private": true,
"dependencies": {
"@angular/animations": "^15.1.0",
"@angular/cdk": "~15.1.5",
"@angular/common": "^15.1.0",
"@angular/compiler": "^15.1.0",
"@angular/core": "^15.1.0",
"@angular/forms": "^15.1.0",
"@angular/material": "~15.1.5",
"@angular/platform-browser": "^15.1.0",
"@angular/platform-browser-dynamic": "^15.1.0",
"@angular/router": "^15.1.0",
"@datorama/akita": "^8.0.1",
"karma-coverage": "^2.2.0",
"karma-jasmine-html-reporter": "^2.0.0",
"karma-spec-reporter": "^0.0.36",
"karma-typescript-mock": "^1.0.1",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"typescript-core": "^9.2.0",
"zone.js": "~0.12.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^15.1.6",
"@angular/cli": "~15.1.6",
"@angular/compiler-cli": "^15.1.0",
"@types/jasmine": "~4.3.0",
"jasmine": "^4.5.0",
"jasmine-core": "~4.5.0",
"jasmine-ts": "^0.4.0",
"karma": "^6.1.0",
"karma-chrome-launcher": "^3.1.1",
"karma-jasmine": "^5.1.0",
"karma-typescript": "^5.5.3",
"ts-node": "^10.9.1",
"typescript": "~4.9.4"
}
}
我的angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"EpicTripApp": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss",
"skipTests": true
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/epic-trip-app",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": [
"zone.js"
],
"tsConfig": "tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"@angular/material/prebuilt-themes/indigo-pink.css",
"src/styles.scss",
"src/theme.scss"
],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"outputHashing": "all"
},
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "EpicTripApp:build:production"
},
"development": {
"browserTarget": "EpicTripApp:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "EpicTripApp:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"polyfills": [
"zone.js",
"zone.js/testing"
],
"tsConfig": "tsconfig.spec.json",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"@angular/material/prebuilt-themes/indigo-pink.css",
"src/styles.scss"
],
"scripts": [],
"karmaConfig": "karma.conf.js"
}
}
}
}
},
"cli": {
"analytics": "b1288342-9e70-43a2-9613-00151ad6c303"
}
}
就我而言,我没有
app.component.spec.ts
文件。在从具有相同角度版本的其他项目中处理它之后,一切都开始工作。
我找到了解决方案。问题出在 Angular.json
"skipTests": true
中。
我只是删除它。我更新了一些软件包
Angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"EpicTripApp": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss",
"skipTests": true <--**HERE**
}
}
...