伊斯坦布尔仪器加载程序找不到 Angular2 组件的源映射。

Posted

技术标签:

【中文标题】伊斯坦布尔仪器加载程序找不到 Angular2 组件的源映射。【英文标题】:Istanbul instrumenter loader can not find source map for Angular2 component. 【发布时间】:2017-03-04 16:51:05 【问题描述】:

我正在尝试使用 karma、jasmine、webpack 搭建 angular2 脚手架,通过关注网上的各种资源来获得更深入的了解。

我正在使用istanbul-instrumenter-loader 进行业力覆盖率报告。

当我运行 npm test 时,我得到以下输出:

ksharifbd:provat Admin$ npm test

> provat@0.0.1 test /Users/Admin/Downloads/kamal/development/self/provat
> karma start ./testconfig/karma/karma.conf.js --browsers Chrome

root directory: /Users/Admin/Downloads/kamal/development/self/provat
source directory: /Users/Admin/Downloads/kamal/development/self/provat/src

webpack: bundle is now VALID.
webpack: bundle is now INVALID.
ts-loader: Using typescript@2.0.3 and /Users/Admin/Downloads/kamal/development/self/provat/tsconfig.json
22 10 2016 18:48:15.719:WARN [karma]: No captured browser, open http://localhost:9876/

webpack: bundle is now VALID.
22 10 2016 18:48:15.741:INFO [karma]: Karma v1.3.0 server started at http://localhost:9876/
22 10 2016 18:48:15.742:INFO [launcher]: Launching browser Chrome with unlimited concurrency
22 10 2016 18:48:15.859:INFO [launcher]: Starting browser Chrome
22 10 2016 18:48:17.420:INFO [Chrome 54.0.2840 (Mac OS X 10.10.4)]: Connected on socket /#m-tmeGM-JMz_OSU4AAAA with id 80103692
Chrome 54.0.2840 (Mac OS X 10.10.4): Executed 1 of 1 SUCCESS (0.129 secs / 0.104 secs)
Error: Could not find source map for: "/Users/Admin/Downloads/kamal/development/self/provat/src/modules/greetings/component/greetings.component.ts"
at /Users/Admin/Downloads/kamal/development/self/provat/node_modules/remap-istanbul/lib/remap.js:257:11
at Array.forEach (native)
at /Users/Admin/Downloads/kamal/development/self/provat/node_modules/remap-istanbul/lib/remap.js:214:22
at Array.forEach (native)
at remap (/Users/Admin/Downloads/kamal/development/self/provat/node_modules/remap-istanbul/lib/remap.js:213:12)
at RemapCoverageReporter.onCoverageComplete (/Users/Admin/Downloads/kamal/development/self/provat/node_modules/karma-remap-coverage/remap-coverage.js:23:23)
at Server.<anonymous> (/Users/Admin/Downloads/kamal/development/self/provat/node_modules/karma/lib/events.js:13:22)
at emitTwo (events.js:106:13)
at Server.emit (events.js:191:7)
at InMemoryReport.writeReport (/Users/Admin/Downloads/kamal/development/self/provat/node_modules/karma-coverage/lib/in-memory-report.js:14:22)
at writeReport (/Users/Admin/Downloads/kamal/development/self/provat/node_modules/karma-coverage/lib/reporter.js:68:16)
at /Users/Admin/Downloads/kamal/development/self/provat/node_modules/karma-coverage/lib/reporter.js:290:11
at Array.forEach (native)
at Collection.forEach (/Users/Admin/Downloads/kamal/development/self/provat/node_modules/karma/lib/browser_collection.js:93:21)
at /Users/Admin/Downloads/kamal/development/self/provat/node_modules/karma-coverage/lib/reporter.js:247:16
at Array.forEach (native)

=============================== Coverage  summary===============================
Statements   : 82.35% ( 14/17 )
Branches     : 48.28% ( 14/29 )
Functions    : 100% ( 4/4 )
Lines        : 91.67% ( 11/12 )
================================================================================

我没有发布多个文件的输出,而是将所有代码in Github with README。

我们将非常感谢您的帮助。

【问题讨论】:

【参考方案1】:

我遇到了同样的问题,“istanbul-instrumenter-loader”存在问题,降级到版本“^0.2.0”可以工作。

更改你的 package.json 并重新安装包

npm un  istanbul-instrumenter-loader --save-dev

npm i istanbul-instrumenter-loader@^0.2.0 --save-dev

这是其中一个文件的覆盖范围

【讨论】:

@Ajay Bhosle,我面临同样的问题,但降级 karma-instrumenter-loader 对我不起作用。这是我发布的问题的链接***.com/questions/40546022/…。你能帮帮我吗? 你找到解决办法了吗? 完整示例请参考github.com/bhosale-ajay/minimalistic-angular-starter-kit【参考方案2】:

我不确定降级 istanbul-instrumenter-loader 是否可行。但是将其降级到最低并不是一个好的做法,而且总是适合。这里的问题是测试加载找不到特定文件的源映射。并且在测试阶段没有必要。因此我们可以通过在angular.json 文件中的测试配置中添加"sourceMap": false 来修复,如下所示。

    "test": 
      "builder": "ngx-build-plus:karma",
      "options": 
        "main": "src/test.ts",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "tsconfig.spec.json",
        "karmaConfig": "karma.conf.js",
        "sourceMap": false,  // <---
        "styles": [
          "src/styles.scss"
        ],
        "scripts": [],
        "assets": [
          "src/favicon.ico",
          "src/assets"
        ]
      
    ,

【讨论】:

以上是关于伊斯坦布尔仪器加载程序找不到 Angular2 组件的源映射。的主要内容,如果未能解决你的问题,请参考以下文章

找不到模块'angular2/angular2'

angular2 找不到名称要求

Angular2:例外:在控件上找不到指令注释

Angular2 - angular2.dev.js:23501 例外:在 ArticleComponent 上找不到指令注释

使用仪器时应用程序在某些操作上崩溃,如何查找原因?

Angular2-signaturepad 与 Angular 一起使用会导致找不到模块错误