Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular Cli-语法错误:';导入&x27;和';出口';只能与';sourceType:module';_Angular_Typescript_Code Coverage_Karma Jasmine_Angular Cli - Fatal编程技术网

Angular Cli-语法错误:';导入&x27;和';出口';只能与';sourceType:module';

Angular Cli-语法错误:';导入&x27;和';出口';只能与';sourceType:module';,angular,typescript,code-coverage,karma-jasmine,angular-cli,Angular,Typescript,Code Coverage,Karma Jasmine,Angular Cli,我正在尝试使用angular cli生成覆盖率报告。然而,我不断得到以下错误。我不太确定这是cli错误还是Karma.conf的问题ng测试/npm测试运行良好。。。那么这和代码覆盖率选项有关吗 Error: Module build failed: SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (3:0) at Parser.pp$5.raise (C:\Deve

我正在尝试使用angular cli生成覆盖率报告。然而,我不断得到以下错误。我不太确定这是cli错误还是Karma.conf的问题<代码>ng测试/
npm测试
运行良好。。。那么这和代码覆盖率选项有关吗

    Error: Module build failed: SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (3:0)
        at Parser.pp$5.raise (C:\Development\source\\node_modules\babylon\lib\index.js:4443:13)
        at Parser.pp$1.parseStatement (C:\Development\source\\node_modules\babylon\lib\index.js:1875:16)
        at Parser.parseStatement (C:\Development\source\\node_modules\babylon\lib\index.js:5795:22)
        at Parser.pp$1.parseBlockBody (C:\Development\source\\node_modules\babylon\lib\index.js:2262:21)
        at Parser.pp$1.parseTopLevel (C:\Development\source\\node_modules\babylon\lib\index.js:1772:8)
        at Parser.parse (C:\Development\source\\node_modules\babylon\lib\index.js:1667:17)
        at Object.parse (C:\Development\source\\node_modules\babylon\lib\index.js:7163:37)
        at Instrumenter.instrumentSync (C:\Development\source\\node_modules\istanbul-lib-instrument\dist\instrumenter.js:121:31)
        at Instrumenter.instrument (C:\Development\source\\node_modules\istanbul-lib-instrument\dist\instrumenter.js:176:32)
        at Object.module.exports (C:\Development\source\\node_modules\istanbul-instrumenter-loader\index.js:25:25),Module build failed: SyntaxError: 'import
    ' and 'export' may appear only with 'sourceType: module' (2:0)
        at Parser.pp$5.raise (C:\Development\source\\node_modules\babylon\lib\index.js:4443:13)
        at Parser.pp$1.parseStatement (C:\Development\source\\node_modules\babylon\lib\index.js:1875:16)
        at Parser.parseStatement (C:\Development\source\\node_modules\babylon\lib\index.js:5795:22)
        at Parser.pp$1.parseBlockBody (C:\Development\source\\node_modules\babylon\lib\index.js:2262:21)
        at Parser.pp$1.parseTopLevel (C:\Development\source\\node_modules\babylon\lib\index.js:1772:8)
        at Parser.parse (C:\Development\source\\node_modules\babylon\lib\index.js:1667:17)
        at Object.parse (C:\Development\source\\node_modules\babylon\lib\index.js:7163:37)
        at Instrumenter.instrumentSync (C:\Development\source\\node_modules\istanbul-lib-instrument\dist\instrumenter.js:121:31)
        at Instrumenter.instrument (C:\Development\source\\node_modules\istanbul-lib-instrument\dist\instrumenter.js:176:32)
        at Object.module.exports (C:\Development\source\\node_modules\istanbul-instrumenter-loader\index.js:25:25)
        at Compiler.compiler.plugin (C:\Development\source\\node_modules\@angular\cli\plugins\karma-webpack-throw-error.js:10:23)
        at Compiler.applyPlugins (C:\Development\source\\node_modules\tapable\lib\Tapable.js:61:14)
        at Watching._done (C:\Development\source\\node_modules\webpack\lib\Compiler.js:91:17)
        at onCompiled (C:\Development\source\\node_modules\webpack\lib\Compiler.js:50:17)
        at C:\Development\source\\node_modules\webpack\lib\Compiler.js:480:13
        at next (C:\Development\source\\node_modules\tapable\lib\Tapable.js:138:11)
        at Compiler.<anonymous> (C:\Development\source\\node_modules\webpack\lib\CachePlugin.js:62:5)
        at Compiler.applyPluginsAsyncSeries (C:\Development\source\\node_modules\tapable\lib\Tapable.js:142:13)
        at C:\Development\source\\node_modules\webpack\lib\Compiler.js:477:10
        at Compilation.applyPluginsAsyncSeries (C:\Development\source\\node_modules\tapable\lib\Tapable.js:131:46)
        at self.applyPluginsAsync.err (C:\Development\source\\node_modules\webpack\lib\Compilation.js:640:19)
        at next (C:\Development\source\\node_modules\tapable\lib\Tapable.js:138:11)
        at Compilation.<anonymous> (C:\Development\source\\node_modules\webpack\lib\ProgressPlugin.js:122:5)
        at Compilation.applyPluginsAsyncSeries (C:\Development\source\\node_modules\tapable\lib\Tapable.js:142:13)
        at self.applyPluginsAsync.err (C:\Development\source\\node_modules\webpack\lib\Compilation.js:631:11)
        at next (C:\Development\source\\node_modules\tapable\lib\Tapable.js:138:11)

今天我遇到了同样的问题,我的案例中的修复是对tsconfig.spec.json文件的更改。我将模块条目从“模块”更改为“es2015” 至
“模块”:“commonjs”


这解决了运行
ng test--cc
时出现的编译错误,并创建了预期的覆盖率报告。希望这有帮助

我今天遇到了同样的问题,我的问题是修改了tsconfig.spec.json文件。我将模块条目从“模块”更改为“es2015” 至
“模块”:“commonjs”

这解决了运行
ng test--cc
时出现的编译错误,并创建了预期的覆盖率报告。希望这有帮助

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular/cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('karma-chrome-launcher'),
      require('@angular/cli/plugins/karma')
    ],
    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', 'json'],
      fixWebpackSourcePaths: true
    },
    reporters: config.angularCli && config.angularCli.codeCoverage
      ? ['progress', 'coverage-istanbul']
      : ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};