无法生成 Angular 中的 karma.conf。

huangapple go评论129阅读模式
英文:

Unable to generate karma.conf in Angular

问题

I am practicing CI/CD and started to configure karma.conf. However, I found that Angular projects no longer have karma.conf, and the official recommendation "ng generate config karma" doesn't work and gives me the following error: "Error: Unknown argument: karma". How can I resolve this issue?

Thank any help!

Here is my version information:

Angular CLI: 15.0.5
Node: 19.7.0 (Unsupported)
Package Manager: npm 9.5.0
OS: darwin x64

Angular: 15.2.1
... animations, cdk, common, compiler, compiler-cli, core, forms
... material, platform-browser, platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.1502.1
@angular-devkit/build-angular 15.2.1
@angular-devkit/core 15.2.1
@angular-devkit/schematics 15.0.5
@angular/cli 15.0.5
@schematics/angular 15.0.5
rxjs 7.5.7
typescript 4.8.4

Yes, here are my package.json, please.

{
"name": "unitest",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"private": true,
"dependencies": {
"@angular/animations": "^15.0.0",
"@angular/cdk": "^15.2.1",
"@angular/common": "^15.0.0",
"@angular/compiler": "^15.0.0",
"@angular/core": "^15.0.0",
"@angular/forms": "^15.0.0",
"@angular/material": "^15.2.1",
"@angular/platform-browser": "^15.0.0",
"@angular/platform-browser-dynamic": "^15.0.0",
"@angular/router": "^15.0.0",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.12.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^15.0.2",
"@angular/cli": "~15.0.2",
"@angular/compiler-cli": "^15.0.0",
"@types/jasmine": "~4.3.0",
"jasmine-core": "~4.5.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"typescript": "~4.8.2"
}
}

英文:

I am practicing CI/CD and started to configure karma.conf. However, I found that Angular projects no longer have karma.conf, and the official recommendation "ng generate config karma" doesn't work and gives me the following error: "Error: Unknown argument: karma". How can I resolve this issue?

Thank any help!

Here is my version information:

Angular CLI: 15.0.5
Node: 19.7.0 (Unsupported)
Package Manager: npm 9.5.0
OS: darwin x64

Angular: 15.2.1
... animations, cdk, common, compiler, compiler-cli, core, forms
... material, platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1502.1
@angular-devkit/build-angular   15.2.1
@angular-devkit/core            15.2.1
@angular-devkit/schematics      15.0.5
@angular/cli                    15.0.5
@schematics/angular             15.0.5
rxjs                            7.5.7
typescript                      4.8.4

Yes, here are my package.json, please.

{
  "name": "unitest",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^15.0.0",
    "@angular/cdk": "^15.2.1",
    "@angular/common": "^15.0.0",
    "@angular/compiler": "^15.0.0",
    "@angular/core": "^15.0.0",
    "@angular/forms": "^15.0.0",
    "@angular/material": "^15.2.1",
    "@angular/platform-browser": "^15.0.0",
    "@angular/platform-browser-dynamic": "^15.0.0",
    "@angular/router": "^15.0.0",
    "rxjs": "~7.5.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.12.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^15.0.2",
    "@angular/cli": "~15.0.2",
    "@angular/compiler-cli": "^15.0.0",
    "@types/jasmine": "~4.3.0",
    "jasmine-core": "~4.5.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "typescript": "~4.8.2"
  }
}

答案1

得分: 3

update your angular version and run

ng g config karma

tested in angular 15.2.2 and it successfully generated

{
  "name": "ang-testing-poc",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^15.2.0",
    "@angular/common": "^15.2.0",
    "@angular/compiler": "^15.2.0",
    "@angular/core": "^15.2.0",
    "@angular/forms": "^15.2.0",
    "@angular/platform-browser": "^15.2.0",
    "@angular/platform-browser-dynamic": "^15.2.0",
    "@angular/router": "^15.2.0",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.12.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^15.2.2",
    "@angular/cli": "~15.2.2",
    "@angular/compiler-cli": "^15.2.0",
    "@types/jasmine": "~4.3.0",
    "jasmine-core": "~4.5.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "typescript": "~4.9.4"
  }
}
英文:

update your angular version and run

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

ng g config karma

<!-- end snippet -->

tested in angular 15.2.2 and it successfully generated

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

{
  &quot;name&quot;: &quot;ang-testing-poc&quot;,
  &quot;version&quot;: &quot;0.0.0&quot;,
  &quot;scripts&quot;: {
    &quot;ng&quot;: &quot;ng&quot;,
    &quot;start&quot;: &quot;ng serve&quot;,
    &quot;build&quot;: &quot;ng build&quot;,
    &quot;watch&quot;: &quot;ng build --watch --configuration development&quot;,
    &quot;test&quot;: &quot;ng test&quot;
  },
  &quot;private&quot;: true,
  &quot;dependencies&quot;: {
    &quot;@angular/animations&quot;: &quot;^15.2.0&quot;,
    &quot;@angular/common&quot;: &quot;^15.2.0&quot;,
    &quot;@angular/compiler&quot;: &quot;^15.2.0&quot;,
    &quot;@angular/core&quot;: &quot;^15.2.0&quot;,
    &quot;@angular/forms&quot;: &quot;^15.2.0&quot;,
    &quot;@angular/platform-browser&quot;: &quot;^15.2.0&quot;,
    &quot;@angular/platform-browser-dynamic&quot;: &quot;^15.2.0&quot;,
    &quot;@angular/router&quot;: &quot;^15.2.0&quot;,
    &quot;rxjs&quot;: &quot;~7.8.0&quot;,
    &quot;tslib&quot;: &quot;^2.3.0&quot;,
    &quot;zone.js&quot;: &quot;~0.12.0&quot;
  },
  &quot;devDependencies&quot;: {
    &quot;@angular-devkit/build-angular&quot;: &quot;^15.2.2&quot;,
    &quot;@angular/cli&quot;: &quot;~15.2.2&quot;,
    &quot;@angular/compiler-cli&quot;: &quot;^15.2.0&quot;,
    &quot;@types/jasmine&quot;: &quot;~4.3.0&quot;,
    &quot;jasmine-core&quot;: &quot;~4.5.0&quot;,
    &quot;karma&quot;: &quot;~6.4.0&quot;,
    &quot;karma-chrome-launcher&quot;: &quot;~3.1.0&quot;,
    &quot;karma-coverage&quot;: &quot;~2.2.0&quot;,
    &quot;karma-jasmine&quot;: &quot;~5.1.0&quot;,
    &quot;karma-jasmine-html-reporter&quot;: &quot;~2.0.0&quot;,
    &quot;typescript&quot;: &quot;~4.9.4&quot;
  }
}

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年3月4日 03:11:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75631014.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定