babel-minify-webpack-plugin icon indicating copy to clipboard operation
babel-minify-webpack-plugin copied to clipboard

error with sourcemaps

Open spielcrypto opened this issue 8 years ago • 36 comments

I reproduce this issue when I use source maps with this plugin. My config file:

const path = require('path')
const webpack = require("webpack");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MinifyPlugin = require("babel-minify-webpack-plugin");

module.exports = {
	entry: path.resolve(__dirname, './app/component/index'),
    devtool: 'source-map',
	output: {
		path: path.resolve(__dirname, './dist'),
		filename: 'app.bundle.js'
	},

	resolve: {
		extensions: ['.ts', '.tsx', '.js', '.jsx']
	},

	module: {
		rules: [{
			test: /\.tsx?$/,
			exclude: /node_modules/,
			loaders: ['ts-loader']
		}, {
			test: /\.css$/,
			include: /node_modules/,
			loaders: ['style-loader', 'css-loader']
		}, {
			test: /\.scss$/,
			use: [{
				loader: "style-loader"
			}, {
				loader: "css-loader"
			}, {
				loader: "sass-loader"
			}]
		}, {
			test: /\.(eot|svg|ttf|woff|woff2)$/,
			loaders: ['file-loader?name=fonts/[name].[ext]']
        }]
    },
    
    plugins: [
        new MinifyPlugin()
    ]
}

The error which I get is this:

/home/razorpack/develop/pyrite-prism/node_modules/webpack-sources/node_modules/source-map/lib/source-map-generator.js:276
        throw new Error(
        ^

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.
    at SourceMapGenerator_validateMapping [as _validateMapping] (/home/razorpack/develop/pyrite-prism/node_modules/webpack-sources/node_modules/source-map/lib/source-map-generator.js:276:15)
    at SourceMapGenerator_addMapping [as addMapping] (/home/razorpack/develop/pyrite-prism/node_modules/webpack-sources/node_modules/source-map/lib/source-map-generator.js:110:12)
    at /home/razorpack/develop/pyrite-prism/node_modules/webpack-sources/node_modules/source-map/lib/source-map-generator.js:72:17
    at Array.forEach (<anonymous>)
    at BasicSourceMapConsumer.SourceMapConsumer_eachMapping [as eachMapping] (/home/razorpack/develop/pyrite-prism/node_modules/webpack-sources/node_modules/source-map/lib/source-map-consumer.js:157:14)
    at Function.SourceMapGenerator_fromSourceMap [as fromSourceMap] (/home/razorpack/develop/pyrite-prism/node_modules/webpack-sources/node_modules/source-map/lib/source-map-generator.js:48:24)
    at SourceMapSource.node (/home/razorpack/develop/pyrite-prism/node_modules/webpack-sources/lib/SourceMapSource.js:32:35)
    at SourceMapSource.proto.sourceAndMap (/home/razorpack/develop/pyrite-prism/node_modules/webpack-sources/lib/SourceAndMapMixin.js:30:18)
    at getTaskForFile (/home/razorpack/develop/pyrite-prism/node_modules/webpack/lib/SourceMapDevToolPlugin.js:33:30)
    at chunk.files.forEach.file (/home/razorpack/develop/pyrite-prism/node_modules/webpack/lib/SourceMapDevToolPlugin.js:91:21)
    at Array.forEach (<anonymous>)
    at /home/razorpack/develop/pyrite-prism/node_modules/webpack/lib/SourceMapDevToolPlugin.js:89:18
    at Array.forEach (<anonymous>)
    at Compilation.<anonymous> (/home/razorpack/develop/pyrite-prism/node_modules/webpack/lib/SourceMapDevToolPlugin.js:88:12)
    at Compilation.applyPlugins1 (/home/razorpack/develop/pyrite-prism/node_modules/tapable/lib/Tapable.js:75:14)
    at self.applyPluginsAsync.err (/home/razorpack/develop/pyrite-prism/node_modules/webpack/lib/Compilation.js:670:11)
    at next (/home/razorpack/develop/pyrite-prism/node_modules/tapable/lib/Tapable.js:202:11)
    at Compilation.<anonymous> (/home/razorpack/develop/pyrite-prism/node_modules/babel-minify-webpack-plugin/dist/index.js:119:11)
    at Compilation.applyPluginsAsyncSeries (/home/razorpack/develop/pyrite-prism/node_modules/tapable/lib/Tapable.js:206:13)
    at self.applyPluginsAsync.err (/home/razorpack/develop/pyrite-prism/node_modules/webpack/lib/Compilation.js:666:10)
    at Compilation.applyPluginsAsyncSeries (/home/razorpack/develop/pyrite-prism/node_modules/tapable/lib/Tapable.js:195:46)
    at sealPart2 (/home/razorpack/develop/pyrite-prism/node_modules/webpack/lib/Compilation.js:662:9)
    at Compilation.applyPluginsAsyncSeries (/home/razorpack/develop/pyrite-prism/node_modules/tapable/lib/Tapable.js:195:46)
    at Compilation.seal (/home/razorpack/develop/pyrite-prism/node_modules/webpack/lib/Compilation.js:605:8)
    at applyPluginsParallel.err (/home/razorpack/develop/pyrite-prism/node_modules/webpack/lib/Compiler.js:508:17)
    at /home/razorpack/develop/pyrite-prism/node_modules/tapable/lib/Tapable.js:289:11
    at _addModuleChain (/home/razorpack/develop/pyrite-prism/node_modules/webpack/lib/Compilation.js:507:11)
    at processModuleDependencies.err (/home/razorpack/develop/pyrite-prism/node_modules/webpack/lib/Compilation.js:477:14)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] production: `webpack --config ./webpack.production.config.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] production script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/razorpack/.npm/_logs/2017-11-09T19_15_16_251Z-debug.log

When I use the source maps without this plugin it works fine. The version plugin is: 0.2.0

spielcrypto avatar Nov 09 '17 19:11 spielcrypto

Could you try to provide a small repo with a file/module where this error occurs ? I'm currently debugging this and a failing example would be quite helpful :)

michael-ciniawsky avatar Nov 10 '17 00:11 michael-ciniawsky

Sure @michael-ciniawsky, this is the repository https://github.com/pyrite-components/pyrite-prism . You have to install as global nodemon and typescript. To reproduce the fail you need to execute npm run production

spielcrypto avatar Nov 10 '17 09:11 spielcrypto

In particular, I found cheap-* source maps work, e.g. module-source-map dies, while cheap-module-source-map does not.

simonbuchan avatar Nov 15 '17 02:11 simonbuchan

Got the same problem, using cheap-source-map instead of source-map doesn't throw error though.

ingro avatar Dec 04 '17 13:12 ingro

Just want to chime in that this is happening to me too. Ref webpack/webpack#5931

For those unfamiliar with cheap-source-map, here's some docs: https://webpack.js.org/configuration/devtool/

timwis avatar Dec 05 '17 11:12 timwis

Running git bisect on this turns up the following commit:

❯ git bisect good
d0a724cec766ea5fbea9ecc514d38f7fd2ee3735 is the first bad commit
commit d0a724cec766ea5fbea9ecc514d38f7fd2ee3735
Author: Joshua Wiens <[email protected]>
Date:   Sat Aug 12 02:50:01 2017 -0500

    refactor: Apply webpack-defaults (#51)

    * refactor: Init webpack-defaults
    * style: Update for defaults
    * chore: Remove legacy babel env setting
    * chore: Update repo & bugs in pacakge.json
    * test: Fix source map test assertion syntax

    BREAKING CHANGE: Enforces `engines` of `"node": ">=4.3.0 < 5.0.0 || >= 5.10`
    BREAKING CHANGE: Enforces `peerDependency` of `"webpack": "^2.0.0 || ^3.0.0`

:100644 100644 354caa95dfed982fff17dafbe378e1b253fdbdba e7e4dbd99b91e6c699aeecd4e21b72594c00093e M	.babelrc
:100644 100644 1a096400cea55f9c0bfd7abb3da880c31ffce53d 1f899991b1335c3b8fc09a137fa5e6269bb2b65e M	.editorconfig
:000000 100644 0000000000000000000000000000000000000000 b2d59d1f7578b05e96f3b3f8a7d5039df3d06fb6 A	.eslintignore
:000000 100644 0000000000000000000000000000000000000000 4016c3eed18c749c8d968ccf89ce374bbb611842 A	.eslintrc
:100644 000000 d98f68986934414fd629c5a9774bcb810a4bf237 0000000000000000000000000000000000000000 D	.eslintrc.js
:000000 100644 0000000000000000000000000000000000000000 b07091b9b12ca11a84f562f56cdb4156712280be A	.gitattributes
:000000 040000 0000000000000000000000000000000000000000 7094ba2f4446b63099d07d17b7663d5412d01a74 A	.github
:100644 100644 8a05de541c440248984dc2b58407e2a327875b31 de347064f4986dab4d1133dc79dde317f7d48c7b M	.gitignore
:100644 100644 ddccd23750a34fbd08773ef6a2d7615c6137835c 76b149227e1523aaecc5a129652073d922571d6d M	.travis.yml
:000000 100644 0000000000000000000000000000000000000000 95fd7360e907a3797f16dcef7b00d4b138d4ca06 A	CHANGELOG.md
:000000 100644 0000000000000000000000000000000000000000 aa4f18a5043eac562724cbfd7f2ec1f5b7764b77 A	appveyor.yml
:000000 100644 0000000000000000000000000000000000000000 0dde8ba5af5e47cfa7fdf40e444f986ac3d6db2c A	package-lock.json
:100644 100644 cce2507527c11f4a2e0f1e4e44d1035dae31da0c 9bb3ec1bb62095452e50c3e4379092b566a6fa4b M	package.json
:040000 040000 908bc17c9eaea633e6821e219a4ca213d945cdd4 e3c1dacbbd18feab5b4451ac516841134d14d79f M	src
:040000 040000 5dc5817b66f78e6ea66ccd3e51410b03f1e1753e 82c3316b8e07d066761dd89486d54ba1ef656838 M	test
:100644 000000 b36b79094e0678df41773b4ed923b7c561459e44 0000000000000000000000000000000000000000 D	yarn.lock

eliperelman avatar Dec 08 '17 18:12 eliperelman

Also having this problem with the 'source-map' option.

bradchoate avatar Dec 12 '17 18:12 bradchoate

Just wanted to chip in and say that in my case it doesn't matter if i use the BabiliPlugin() or not, as long as I don't have the "webpack-sources": "1.0.1" installed it always fails.

Also wanted to provide you with my files used:

Cases

  • npm run server -> no error
  • npm run server:test -> error (if [email protected] is not explicitly installed)
  • npm run build:prod -> no error

nealoke avatar Dec 16 '17 16:12 nealoke

I'm running into the same problem. I worked around it by pinning babili-webpack-plugin to 0.1.1.

cf. https://github.com/webpack/webpack/issues/5931#issuecomment-345214746

Alfredo-Delgado avatar Dec 18 '17 16:12 Alfredo-Delgado

So what's going on here? It seems like a breaking commit has been identified and that, most of the time, cheap-* avoids the problem while others don't. Do we need more repro examples?

saiichihashimoto avatar Jan 04 '18 05:01 saiichihashimoto

I'd guess cheap-* "fixing" it is since IIRC that disables minification source mapping (not much point mapping line-by-line if you only output one line!), but that doesn't narrow it down much. Seems there are plenty of references to this, so probably plenty of repro cases, just needs someone to spend the time on it.

simonbuchan avatar Jan 04 '18 06:01 simonbuchan

I'm also facing this issue.

arbaaz avatar Jan 04 '18 07:01 arbaaz

Problem still exists? If yes please create minimum reproducible test repo. Thanks!

alexander-akait avatar Feb 02 '18 11:02 alexander-akait

I commented out BabiliPlugin and it was working.

// new BabiliPlugin()

arbaaz avatar Feb 02 '18 11:02 arbaaz

@arbaaz Incredible solution :trollface:

alexander-akait avatar Feb 02 '18 11:02 alexander-akait

I feel a bit bad about saying this, but I changed to Uglify-es and got very good results both wrt to compilation speed and sourcemaps.

tarjei avatar Feb 02 '18 11:02 tarjei

@tarjei i near future i implement cache and parallels, first we need fix bugs

alexander-akait avatar Feb 02 '18 11:02 alexander-akait

@evilebottnawi 👍

tarjei avatar Feb 02 '18 11:02 tarjei

@evilebottnawi I have the similiar problem, and here is demo.

ghost avatar Feb 05 '18 12:02 ghost

@le93us thanks!

alexander-akait avatar Feb 05 '18 12:02 alexander-akait

We upgrade babel-preset-minify from 0.2.0 to 0.3.0, in theory it can be solve this problems. Somebody can check problem again?

alexander-akait avatar Feb 07 '18 16:02 alexander-akait

Still the same error here after yarn upgrade babel-minify-webpack-plugin (babel-preset-minify@^0.3.0 in dependencies).

ojab avatar Feb 07 '18 17:02 ojab

@ojab Thanks!

alexander-akait avatar Feb 07 '18 17:02 alexander-akait

I can reproduce the above as well. I am working around it by adding an explicit dependency on "webpack-sources": "1.0.1". Before I did this was using "webpack-sources": "1.1.0" in the generated package-lock.json.

My config file is virtually identical to the one given in the first comment. node: v8.9.4 npm: v5.6.0

Fzzr avatar Feb 07 '18 22:02 Fzzr

0.3.0

Problem is not solved.

ghost avatar Feb 10 '18 07:02 ghost

I was also able to work around the problem by forcing webpack-sources from 1.1.0 to 1.0.1. Thank you @Fzzr

blittle avatar Feb 14 '18 01:02 blittle

Somebody other can confirm what upgrade webpack-source solve problem?

alexander-akait avatar Feb 14 '18 09:02 alexander-akait

AFAIU 1.1.0 is the last version for webpack-sources, the issue is reproducible with it.

ojab avatar Feb 14 '18 11:02 ojab

@evilebottnawi I tried both [email protected] and [email protected], still having:

 92% after chunk asset optimization SourceMapDevToolPlugin index.js generate SourceMap/Users/damz/Desktop/yarsk/node_modules/webpack-sources/node_modules/source-map/lib/source-map-generator.js:276
        throw new Error(
        ^

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.
    at SourceMapGenerator_validateMapping [as _validateMapping] (/Users/damz/Desktop/yarsk/node_modules/webpack-sources/node_modules/source-map/lib/source-map-generator.js:276:15)

Temporarily disabling sourcemaps with config.devtool = false until solution is found.

damianobarbati avatar Feb 25 '18 14:02 damianobarbati

@d3viant0ne as the author of the regressing commit (see bisect in https://github.com/webpack-contrib/babel-minify-webpack-plugin/issues/68#issuecomment-350342659) - I don't suppose you have any ideas as to what might have caused this? :-)

edmorley avatar Mar 09 '18 21:03 edmorley