question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sourcemaps with normal Usage, not Alternative usage

See original GitHub issue

We’re having troubles trying to make source maps work with typescript spec source files and main source files.

If we stick with the Alternative usage described here, then generate source maps as suggested in following section here, we can happily browse typescript code from Chrome developer tools while debugging tests.

If we stick with the basic usage described here, and we load spec files through karma.conf.js, instead of require-ing them in test shim single entry point, it looks like sourcemaps stop working. Browser developer tools only show JS webpack-prepared bundles, not original typescript source files.

Is this second way feasible at all? Can anybody explain how to get there? Thanks for your time!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:4
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

65reactions
sshevcommented, Jun 9, 2016

Here’s native solution to make source map work in typescript unit tests: include SourceMapDevToolPlugin plugin to webpack config and configure it to process .ts files as well:

plugins: [
  new webpack.SourceMapDevToolPlugin({
    filename: null, // if no value is provided the sourcemap is inlined
    test: /\.(ts|js)($|\?)/i // process .js and .ts files only
  })
]
11reactions
donaldpipowitchcommented, Apr 25, 2016

I can verify this with a simple test:

// karma.conf.js
module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: [ 'mocha' ],
    files: [ 'test/unit.js' ],
    preprocessors: {
      'test/unit.js': [ 'webpack', 'sourcemap' ]
    },
    plugins: [
      'karma-mocha',
      'karma-phantomjs-launcher',
      'karma-sourcemap-loader',
      'karma-webpack',
      'karma-spec-reporter'
    ],
    reporters: [ 'spec' ],
    browsers: [ 'PhantomJS' ],
    singleRun: true,
    webpack: {
      devtool: 'inline-source-map',
      module: {
        loaders: [
          {
            test: /\.ts(x?)$/,
            loader:
              `babel?` +
              `presets[]=${require.resolve('babel-preset-es2015')},` +
              `presets[]=${require.resolve('babel-preset-stage-0')}` +
              `!ts`
          }
        ]
      }
    },
    webpackMiddleware: {
      noInfo: true
    }
  })
}
// test/unit.js
require('./foo-unit.ts');
// test/foo-unit.ts
throw new Error('test');

Outputs

  Error: test
  at /Users/my-name/Workspace/test/test/unit.js:7594 <- webpack:///test/foo-unit.ts:1:0

This works nice. But let us change test/unit.js to test/unit.ts:

// karma.conf.js
...
    files: [ 'test/unit.ts' ],
    preprocessors: {
      'test/unit.ts': [ 'webpack', 'sourcemap' ]
    },
...
// test/unit.ts
import './foo-unit.ts';

Outputs

  Error: test
  at /Users/my-name/Workspace/test/test/unit.ts:7595

The mapping is lost.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sourcemaps with normal Usage, not Alternative usage #109
We're having troubles trying to make source maps work with typescript spec source files and main source files.
Read more >
Source Maps not working with Webpack - Stack Overflow
In bundle.js you will see original transpiled webpack bundle - this is normal behaviour. Open webpack:// and you will see your project files ......
Read more >
Configuring Sentry with JavaScript Source Maps
An epic troubleshooting tale to enable JavaScript source map fetching in Sentry.
Read more >
Using sourcemaps on production without exposing the source ...
There is a good solution for this issue — sourcemaps. It allows you to debug minified code as if it was unmodified. It's...
Read more >
How to Use Source Maps in TypeScript Lambda Functions ...
Stack Traces; Emitting Source Maps; Source Map Support; CDK Example ... AWS does not publish the minor versions in use in Lambda, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found