11

Is it possible to configure Karma to use source map files for stacktraces? I see that there are a few issues on GitHub which appear to have been closed? I can't however find any example of doing so.

If this is supported can someone illustrate an example config?

cirrus
  • 5,624
  • 8
  • 44
  • 62

2 Answers2

12

In your karma.config.js file add

config.set({
files: [{
        pattern: '**/*.js.map',
        included: false
      },
...
});

This has worked for me, and files are now served by karma.

Mihai Lazar
  • 2,249
  • 2
  • 19
  • 27
  • I also had to add the same entry for the mapped `angular.js` file to be served by the karma HTTP server. – idleherb Jun 04 '16 at 17:51
7

You need a preprocessor to look at source maps in karma: have a look at karma-sourcemap-loader to preprocess your data and locate the source map files. A limitation of the library is that the source maps must be in the same folder as the js files, with the same name - but different extension of course.

MarcoL
  • 9,829
  • 3
  • 37
  • 50
  • Thanks! I've installed the loader, done the 'npm install' thing, added the preprocessor directive to my conf.js file but now I get "Can not load "sourcemap", it is not registered!", "Are you missing a plugin?" – cirrus Mar 07 '14 at 13:07
  • 2
    You have to list all the plugins you are using in the configuration file: I had the same issue with the coverage one http://stackoverflow.com/questions/18069865/unable-to-run-coverage-with-karma?rq=1 – MarcoL Mar 07 '14 at 17:02
  • 1
    I still can't get this to work. I've done the 'npm install karma-sourcempa-loader --save-dev', added a 'preprocessors' section as well as 'plugins' section, but I now get, "Cannot find plugin "karma-sourcemap-loader". Did you forget to install it? – cirrus Mar 19 '14 at 11:51
  • 1
    karma-sourcemap-loader now supports inline source maps. It had a bug until recently that would cause it to fail if the inline source map was followed by the unix-y blank line. – Carl G Feb 02 '15 at 21:57
  • @cirrus did you solve the issue? i have the same problem/error – David Sep 17 '16 at 21:12
  • Nope. I never did. I'd been trying to get the support for TypeScript but despite several attempts following others' suggestions I never could, and had to manage without. – cirrus Sep 20 '16 at 07:51
  • Note: I was unable to get this to work until I added the plugin to the list of plugins for Karma: `plugins: [ 'karma-sourcemap-loader' ],` – John Munsch Dec 13 '18 at 15:07