- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
当通过 angular-cli (ng test -cc) 运行具有代码覆盖率的测试时,karma 会抛出以下错误。罪魁祸首似乎是 istanbul 代码覆盖模块,因为在没有 -cc 的情况下运行测试不会导致任何错误。
错误(我用***替换了本地路径):
at Object.exports.default (***\node_modules\istanbul-instrumenter-loader\dist\index.js:25:16),Module build failed: SyntaxError: 'import' and 'export' may appear only with 'sourceType: "module"' (1:0)
at Parser.pp$5.raise (***\node_modules\babylon\lib\index.js:4454:13)
at Parser.pp$1.parseStatement (***\node_modules\babylon\lib\index.js:1881:16)
at Parser.parseStatement (***\node_modules\babylon\lib\index.js:5910:22)
at Parser.pp$1.parseBlockBody (***\node_modules\babylon\lib\index.js:2268:21)
at Parser.pp$1.parseTopLevel (***\node_modules\babylon\lib\index.js:1778:8)
at Parser.parse (***\node_modules\babylon\lib\index.js:1673:17)
at Object.parse (***\node_modules\babylon\lib\index.js:7305:37)
at Instrumenter.instrumentSync (***\node_modules\istanbul-lib-instrument\dist\instrumenter.js:121:31)
at Instrumenter.instrument (***\node_modules\istanbul-lib-instrument\dist\instrumenter.js:176:32)
at Object.exports.default (***\node_modules\istanbul-instrumenter-loader\dist\index.js:25:16)
at Compiler.compiler.plugin (***\node_modules\@angular\cli\plugins\karma-webpack-throw-error.js:10:23)
at Compiler.applyPlugins (***\node_modules\tapable\lib\Tapable.js:61:14)
at Watching._done (***\node_modules\webpack\lib\Compiler.js:92:17)
at onCompiled (***\node_modules\webpack\lib\Compiler.js:51:17)
at ***\node_modules\webpack\lib\Compiler.js:494:13
at next (***\node_modules\tapable\lib\Tapable.js:202:11)
at Compiler.<anonymous> (***\node_modules\webpack\lib\CachePlugin.js:62:5)
at Compiler.applyPluginsAsyncSeries (***\node_modules\tapable\lib\Tapable.js:206:13)
at ***\node_modules\webpack\lib\Compiler.js:491:10
at Compilation.applyPluginsAsyncSeries (***\node_modules\tapable\lib\Tapable.js:195:46)
at self.applyPluginsAsync.err (***\node_modules\webpack\lib\Compilation.js:645:19)
at next (***\node_modules\tapable\lib\Tapable.js:202:11)
at Compilation.compilation.plugin (***\node_modules\webpack\lib\ProgressPlugin.js:121:6)
at Compilation.applyPluginsAsyncSeries (***\node_modules\tapable\lib\Tapable.js:206:13)
at self.applyPluginsAsync.err (***\node_modules\webpack\lib\Compilation.js:636:11)
at next (***\node_modules\tapable\lib\Tapable.js:202:11)
package.json:
{
"name": "texteditorapplication",
"version": "1.1.0",
"license": "MIT",
"scripts": {
***
},
"private": true,
"dependencies": {
"@angular/animations": "4.2.3",
"@angular/common": "4.2.3",
"@angular/compiler": "4.2.3",
"@angular/core": "4.2.3",
"@angular/forms": "4.2.3",
"@angular/http": "4.2.3",
"@angular/platform-browser": "4.2.3",
"@angular/platform-browser-dynamic": "4.2.3",
"@angular/router": "4.2.3",
"@ngrx/core": "1.2.0",
"@ngrx/db": "2.0.2",
"@ngrx/effects": "2.0.3",
"@ngrx/router-store": "1.2.6",
"@ngrx/store": "2.2.2",
"@ngrx/store-devtools": "3.1.0",
"@ngrx/store-log-monitor": "3.0.2",
"bootstrap": "3.3.7",
"core-js": "2.4.1",
"linqts": "1.8.2",
"loader-utils": "^1.1.0",
"ngrx-store-freeze": "0.1.0",
"ngx-bootstrap": "2.0.0-beta.2",
"rxjs": "5.4.1",
"web-animations-js": "2.2.2",
"typescript": "2.3.4",
"zone.js": "0.8.6"
},
"devDependencies": {
"@angular/cli": "1.2.7",
"@angular/compiler-cli": "4.2.3",
"@ngrx/store": "^2.2.1",
"@types/jasmine": "2.5.38",
"@types/node": "6.0.64",
"@types/reflect-metadata": "0.0.5",
"codelyzer": "2.0.1",
"copyfiles": "1.2.0",
"enhanced-resolve": "3.3.0",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "3.2.0",
"karma": "1.7.1",
"karma-chrome-launcher": "2.0.0",
"karma-cli": "1.0.1",
"karma-jasmine": "1.1.0",
"karma-jasmine-html-reporter": "0.2.2",
"karma-phantomjs2-launcher": "v0.5.0",
"karma-coverage-istanbul-reporter": "1.3.0",
"istanbul-instrumenter-loader": "3.0.0",
"less-cli": "1.0.0",
"phantomjs-prebuilt": "v2.1.16",
"protractor": "5.1.0",
"rimraf": "2.6.1",
"ts-node": "2.0.0",
"tslint": "4.5.0",
"typescript": "2.3.4"
}
}
业力.conf.json
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular/cli'],
plugins: [
require('@angular/cli/plugins/karma'),
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
files: [
{ pattern: './src/test.ts', watched: false }
],
preprocessors: {
'./src/test.ts': ['@angular/cli']
},
mime: {
'text/x-typescript': ['ts', 'tsx']
},
coverageIstanbulReporter: {
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev'
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'coverage-istanbul']
: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_DEBUG,
autoWatch: true,
browsers: ['ChromeHeadless'],
customLaunchers: {
"ChromeHeadless": {
base: 'Chrome',
flags: ['--headless', '--remote-debugging-port=9222', '--no-sandbox']
}
},
singleRun: false
});
};
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"module": "es6",
"typeRoots": [
"node_modules/@types"
],
"paths": {
"@angular/*": [
"../node_modules/@angular/*"
],
"@ngrx/*": [
"../node_modules/@ngrx/*"
],
"ngx-bootstrap/*": [
"../node_modules/ngx-bootstrap/*"
],
"rxjs/*": [
"../node_modules/rxjs/*"
],
"afw/*": [
"../node_modules/afw/*"
]
},
"lib": [
"es2016",
"dom"
]
}
}
tsconfig.spec.json
{
"extends": "../tsconfig.json",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"module": "commonjs",
"target": "es5",
"outDir": "../out-tsc/spec",
"baseUrl": "",
"types": [
"jasmine",
"node"
],
"traceResolution": true
},
"files": [
"test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}
请帮忙,因为我似乎无法找到解决方案,现在也失去了在遇到此错误时不翻转 table 的能力。我这里的 table 快用完了。
最佳答案
karma.conf.js
config.set({
...
files: [
'test/index.js'
],
preprocessors: {
'test/index.js': 'webpack'
},
webpack: {
...
module: {
rules: [
// instrument only testing sources with Istanbul
{
test: /\.js$/,
use: { loader: 'istanbul-instrumenter-loader' },
include: path.resolve('src/components/')
}
]
}
...
},
reporters: [ 'progress', 'coverage-istanbul' ],
coverageIstanbulReporter: {
reports: [ 'text-summary' ],
fixWebpackSourcePaths: true
}
...
});
写在https://www.npmjs.com/package/istanbul-instrumenter-loader你应该将你的包包含在 karma.conf.js 中;
您的 conf 中只有 instanbul-reporter
而没有 instrumenter-loader
。尝试添加它。
希望对您有所帮助
关于angular - 模块构建失败 : SyntaxError: 'import' and 'export' may appear only with 'sourceType: "module"',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47812436/
我在 Python 2 中尝试了这段代码: def NewFunction(): return '£' 但我收到一条错误消息: SyntaxError: Non-ASCII character
我正在学习xpath,并且我正尝试从html usint xpath获取一些数据 我发现谷歌浏览器可以选择“复制xpath”,效果很好 但不适用于这个例子 some divs
我是 ruby 的初学者。我想修复其中一个邮件软件中的错误。我应用的修复代码如下: @headers[:recipient] = { "To" => (cc.map do |p|
我是初学者级别的python用户,当我在终端中键入以下内容时: $ pydoc Inleesgenbank.py 我收到以下错误消息: ./Inleesgenbank.py中的问题-:语法无效(Inl
我正在编写用于解析电子邮件的脚本,但是以下部分的for循环上有一些SyntaxError: def main(): writer = csv.DictWriter(open('feature
我正在尝试在python33中创建分发文件,但没有成功。 我用嵌套器名称创建了一个文件夹,并在Windows 8的C驱动程序中放入了python33。 此文件夹有2个文件。 nester.py和set
当我尝试导入NumPy时,突然出现以下错误: 更具体地说,它在我键入时显示: import numpy as np 要不就: import numpy 它也会在Python控制台中发生,如下所示: P
在我的 HTML 文件中,我有一行(如下)通过 WiFi 从设备获取响应并使数据可用于我的 JavaScript,它运行良好,除非响应文本中有错误并停止。 响应是一个代表 JavaScript 变量的
我开始使用 Javascript OOP,我编写了我的第一个类,但我在控制台中收到消息错误 这是类(class): class Quote{ deleteQuote(callback){ $(
我正在使用argparse来解析参数,但是当我得到args.global时,出现了一个奇怪的错误,我不知道我哪里做错了 ... parser.add_argument('-u','--update',
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我正在使用argparse来解析参数,但是当我得到args.global时,出现了一个奇怪的错误,我不知道我哪里做错了 ... parser.add_argument('-u','--update',
有什么不同?为什么它会在函数 a() 中出错? function a(){ 1 == 1 ? return true: ""; // Uncaught SyntaxError: Unexpe
我有一个 python 脚本,其中包含如下函数参数的类型声明: def dump_var(v: Variable, name: str = None): 据我所知,这是一个为函数设置输入参数类型的有效
我正在尝试从命令行运行 Python 脚本,这是我的脚本: import sys def printsomething(sys.argv): text = str(sys.argv[1])
我在 macbook 上使用终端将数据打印到打开的文件中: >>> out=open("test_output.txt","w") >>> print("hello",file=out) File
我想排除以下代码产生的错误,但我不知道如何。 from datetime import datetime try: date = datetime(2009, 12a, 31) except:
我想在动态生成的列表中放置一个 onclick 事件。我不能按原样使用它,例如 updateRoomID(arg) ,因为它会立即开火。所以我把它放在一个匿名函数中,按照网上各种来源的建议:funct
我有以下脚本: 测试.py: import sys try: import random print random.random() except: print sys.exc
这个问题在这里已经有了答案: "+=" causing SyntaxError in Python (6 个答案) 关闭 3 年前。 在我的代码中有这些行: if numVotes == 0:
我是一名优秀的程序员,十分优秀!