aurelia: Webpack typescript setup doesn't generate correct souremap

๐Ÿ› Bug Report

The source map for .ts file is not against original user source file, but a modified source file done by @aurelia/webpack-loader.

๐Ÿค” Expected Behavior

It should display original source in debugger.

๐Ÿ˜ฏ Current Behavior

Our webpack-loader did generate the initial source map https://github.com/aurelia/aurelia/blob/1bdb122cd1af090b298c934325d917b9bd494949/packages/webpack-loader/src/index.ts#L34, but the ts-loader ignored incoming source map. This is a well known issue in ts-loader since 2017. https://github.com/TypeStrong/ts-loader/issues/552

๐Ÿ’ Possible Solution

Not sure what can be done, as ts-loader assumes itโ€™s the first loader in the chain.

For reference, ts-loader only reads file contents but not the existing source map. https://github.com/TypeStrong/ts-loader/blob/172ebeb10cc8d15b91eca0828943bf7b962b4366/src/index.ts#L35

๐Ÿ”ฆ Context

In our webpack-loader, the incoming sourcemap is ignored but thatโ€™s fine, because our loader is the first to be run in the loader chain. The problem is that ts-loader assumes itโ€™s the first loader too. In comparison, webpack+babel does give you correct source map.

๐Ÿ’ป Code Sample

๐ŸŒ Your Environment

Software Version(s)
Aurelia
Language
Browser
Bundler
Operating System
NPM/Node/Yarn

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (16 by maintainers)

Commits related to this issue

Most upvoted comments

I packed a ts-loader with support for source map mapping. If you want to try:

npm install --save-dev @bojanv55/ts-loader

and then in webpack config:

     {
        test: /\.ts$/i,
        use: ['@bojanv55/ts-loader', '@aurelia/webpack-loader'],
        exclude: /node_modules/
      },

I had this problem myself after testing out a TypeScript/Webpack project created using today with latest version of npx makes aurelia. All breakpoints were gray (not effective) in VSCode when debugging using โ€œDebugger for Chromeโ€ extension.

After setting the sourceMap property in the scaffolded tsconfig.json:

{
  "sourceMap": true
}

โ€ฆI was able to set breakpoints that were active (red), but the breakpoints positions act weird - I guess that indicates that lines and character positions are off in the source maps.

I then changed the devtool property in webpack.config.js from inline-source-map to eval-cheap-source-map. Now everything works as expected.

module.exports = function(env, { analyze }) {
  const production = env.production || process.env.NODE_ENV === 'production';
  return {
    // ...
    devtool: production ? undefined : 'eval-cheap-source-map', // earlier: 'inline-source-map'
    // ...
  };
}

I guess these things should be updated in the code scaffolding for makes with WebPack/TypeScript