Macil / browserify-hmr

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

TypeError: Invalid attempt to destructure non-iterable instance #3

Open gaearon opened 8 years ago

gaearon commented 8 years ago
  1. Check out reactTransform branch
  2. Add a new file to the example (e.g. stuff.js)
  3. npm start the example
  4. Write require('./stuff'); in label.jsx

Expected: the file is normally imported. Actual: TypeError: Invalid attempt to destructure non-iterable instance.

The error is being caught by the HMR code, but it seems thrown at the module evaluation time.

screen shot 2015-09-20 at 16 20 00

If you enable "pause on caught exceptions" in Chrome debugger, you'll see that the original exception happens during evaluation of the label.jsx code:

screen shot 2015-09-20 at 16 19 36

What strikes me as odd is that _interopRequireDefault Babel helper seems to actually point to sliced-to-array helper (note the filename in the popup). It explains the weird exception: _interopRequireDefault is a function that checks export for default, but slicedToArray is a completely different helper that expects an iterable.

It appears that something in the HMR machinery causes module IDs to get messed up, so require() made by Babel to one of its runtime utilities resolves to a different utility.

gaearon commented 8 years ago

(I should say that, of course, refreshing helps. The mess up only occurs when label.jsx is reevaluated after a newly added file is imported.)

Macil commented 8 years ago

Thanks for the clear bug report! I'll look into this soon. There's a few issues I've seen that have to do with files being added or removed from the bundle at runtime.

fritx commented 8 years ago

damn.. I met this error msg when I wrote const [a, b] = (null)

electriccode commented 6 years ago

I met this when I wrote const [,field2,field3] = componentsArray;