Macil / browserify-hmr

Hot Module Replacement plugin for Browserify
MIT License
373 stars 26 forks source link

bundle fails when required a module from npm that uses its own browserify transform #9

Open royriojas opened 8 years ago

royriojas commented 8 years ago

Hi I just stumbled upon this issue:

When I try to use this module dtektor and at the same time I try to use browserify-hmr

I have made a small example repo for this issue: https://github.com/royriojas/browserify-hmr/tree/fail-source-map

npm start

> example@0.1.0 start /Users/roy/royws/browserify-hmr/example
> ./scripts/run

Starting up http-server, serving ./
Available on:
  http:127.0.0.1:8080
  http:10.211.55.2:8080
  http:10.37.129.2:8080
  http:192.168.1.3:8080
Hit CTRL-C to stop the server
17:59:50 GMT-0500 (PET) [HMR] Emitting updates
17:59:50 GMT-0500 (PET) [HMR] Listening on localhost:3123
TypeError: Cannot read property 'substr' of undefined

This is what I get, the important part is this one:

TypeError: Cannot read property 'substr' of undefined

Apparently it fails when try to alter the source map of the previous run. I have done some investigation and it seems that fails here:

var node = new sm.SourceNode(null, null, null, [
   new sm.SourceNode(null, null, null, header),
   sm.SourceNode.fromStringWithSourceMap(row.source, new sm.SourceMapConsumer(inputMap)),
   new sm.SourceNode(null, null, null, footer)
]);

because the row.source does not correspond to the inputMap, because the transform altered the code.