0

According to the "Production" webpack guide, I'm trying to add source map support to the production/release build.

However I get an exception when I try to run webpack in production mode with the following npm script: webpack --mode production -p --devtool source-map. All it does is:

  • set the mode to production
  • the -p argument is a: shortcut for --optimize-minimize --define process.env.NODE_ENV="production"
  • and set the devtool to source-map

The exception

Unhandled rejection Error: original.line and original.column are not numbers -- you probably meant to omit the original mapping entirely and only map the generated position. If so, pass null for the original mapping instead of an object with empty or null values.

tsconfig

{
  "compilerOptions": {
    "outDir": "./dist",
    "target": "es5",
    "module": "commonjs",
    "strict": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "noUnusedParameters": true,
    "sourceMap": true
  },
  "include": [
    "src/**/*"
  ]
}

webpack config

const path = require('path');

module.exports = {
  entry: './src/app.ts',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  resolve: {
    extensions: ['.js', '.ts']
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        exclude: /node_modules/,
        loader: 'ts-loader'
      }
    ]
  }
};

What I've tried

First, I followed a TypeScript guide. They used source mapping as well - the main difference is the source-map-loader, however dropping in the code below to the rules does not help:

{
  enforce: 'pre',
  test: /\.js$/,
  loader: 'source-map-loader'
}

Then, I tried to mess with the source map options; in the tsconfig changed the sourceMap to inlineSourceMap, in the webpack config the source-map to inline-source-map (despite it is not recommended according to the webpack guide), but no success.

Lastly, adding the mode and devtool to the webpack config does not change anything, so passing these as arguments seems fine.


Update

I thought I make a mini repro project so I stripped out any additional loaders (eg. sass-loader). And everything worked fine. So I assume that there is a compatilibity problem with one of the loaders.


Update 2

After some days of hard-trying to solve this issue, I finally deleted the package-lock file and the node_modules folder. I ran npm install then everything works fine...

1 Answer 1

2

This appears to be a bug that existed in terser version 4.0.1 (a dependency of webpack) and was fixed in version 4.0.2. Version 4.0.2 was released just yesterday (2019-06-30). Deleting and remaking your lock file caused npm/yarn to upgrade to the fixed version.

For anyone else having this problem, try running:

npm upgrade webpack terser

or

yarn upgrade webpack terser
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.