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
modetoproduction - the
-pargument is a:shortcut for --optimize-minimize --define process.env.NODE_ENV="production" - and set the
devtooltosource-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...