错误信息
zengwe$ ng test
Your global Angular CLI version (7.3.8) is greater than your local
version (6.1.0).
The local Angular CLI version is used.
To disable this warning use "ng config -g cli.warnings.versionMismatch false".
06 08 2019 14:59:37.783:ERROR
[config]: Error in config file!
Error: In Angular CLI >6.0 the Karma plugin is now exported by "@angular-devkitild-angular" instead.
Please replace "@angular/cli" with "@angular-devkitild-angular" in your "karma.conf.js" file.
at Object.<anonymous> (**\node_modules\@angular\cli\plugins\karma.js:1:7)
at Module._compile (internal/moduless/loader.js:701:30)
at Object.Module._extensions..js (internal/moduless/loader.js:712:10)
at Module.load (internal/moduless/loader.js:600:32)
at tryModuleLoad (internal/moduless/loader.js:539:12)
at Function.Module._load (internal/moduless/loader.js:531:3)
at Module.require (internal/moduless/loader.js:637:17)
at require (internal/moduless/helpers.js:22:18)
at module.exports (C:\Users\34217\Desktop\kzzbim\Rn\karma.conf.js:13:7)
at Object.parseConfig (C:\Users\34217\Desktop\kzzbim\Rn\node_modules\karma\lib\config.js:421:5)
at new Server (C:\Users\34217\Desktop\kzzbim\Rn\node_modules\karma\lib\server.js:63:24)
at Observable.rxjs_1.Observable.obs [as _subscribe] (**\node_modules\@angular-devkit\
uild-angular\src\karma\packages\angular_devkit\build_angular\src\karma\index.ts:110:29)
at Observable._trySubscribe (C:\Users\34217\Desktop\kzzbim\Rn\node_modules\rxjs\src\internal\Observable.ts:224:19)
at Observable.subscribe (C:\Users\34217\Desktop\kzzbim\Rn\node_modules\rxjs\src\internal\Observable.ts:205:14)
at **\node_modules\rxjs\src\internal\util\subscribeTo.ts:22:23
at Object.subscribeToResult (**\node_modules\rxjs\src\internal\util\subscribeToResult
ts:25:29)
解决办法
更改./karma.conf.js中的frameworks和plugins更改一下
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular/cli/plugins/karma')
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev'
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev'
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
以上问题解决后会报错
ERROR in ./src/polyfills.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: **\src\polyfills.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
at AngularCompilerPlugin.getCompiledFile (**\node_modules\@ngtools\webpack\src\packages\ngtools\webpack\src\angular_compiler_plugin.ts:1028:15)
at plugin.done.then (**\node_modules\@ngtools\webpack\src\packages\ngtools\webpack\src\loader.ts:49:29)
at process._tickCallback (internal/process/next_tick.js:68:7)
@ multi ./src/polyfills.ts ./node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/jit-polyfills.js polyfills[0]
修改tsconfig.spec.json
在include数组中添加"**/polyfills.ts"