thlorenz / proxyquireify

browserify >= v2 version of proxyquire. Mocks out browserify's require to allow stubbing out dependencies while testing.
MIT License
151 stars 24 forks source link

proxyquireify + babelify causes "Invalid mapping" error when browserify debug=true and file contains a comment #57

Closed rally25rs closed 8 years ago

rally25rs commented 8 years ago

Using:

The file being browserified contains only:

window.x = 1; // comment

The existence of the code comment along with the debug:true option for browserify combined causes the error:

Fatal error: Invalid mapping: {"generated":{"line":87,"column":13},"source":"testfile.js","original":{},"name":null}

If debug is set to false then there is no error. -or- if the comment is removed from the file then there is no error.


Minimal example here: https://github.com/rally25rs/test-babelify

Can be cloned, then run npm install and node runner.js or just npm start to reproduce the error.

This will execute:

browserify('testfile.js', { debug: true })
  .transform(babelify, {presets: ['es2015']})
  .plugin(proxyquire.plugin)
  .bundle()
  .pipe(fs.createWriteStream('testfile.browserify.js'));
rally25rs commented 8 years ago

Quick update; this is due to sourceMap handling. If Babelify inserts source maps, then Proxyquireify errors on them.

Using these settings:

browserify({debug: true}).transform("babelify", {sourceMaps: false});

Babelify won't generate sourceMaps and Proxyquireify will, which succeeds ( 😄 ), but the post-transpiled (non-es6) source is shown in the browser (aww 😞 ).

Is there a way to get Proxyquireify to pass-through the Babelify source maps correctly? It seems like Proxyquireify just wraps the default browser-pack module, so I'm surprised it doesn't work...

rally25rs commented 8 years ago

I spent many hours debugging this issue, found that it is due to Proxyquireify using a version of browser-pack from Oct 2014 (dependency on ^3.0.0, current is 6.x).

This was fixed already by: https://github.com/thlorenz/proxyquireify/commit/70852af38f58f3fdc1a41f13221fa135dfa59121

(verified the fix by pointing my project directly to the github url instead of an npm version)

However the deployed NPM version wasn't bumped, so NPM install still gets 3.1.1 that was dependent on browser-pack@3.


Can someone please bump the Proxyquire version and npm publish this commit that updates browser-pack? @thlorenz

bendrucker commented 8 years ago

Published 3.2.0.