Comandeer / rollup-plugin-babel-minify

Simple rollup plugin for minifying code using babel-preset-minify.
MIT License
48 stars 6 forks source link

Cannot read property 'names' of null #1

Closed FezVrasta closed 7 years ago

FezVrasta commented 7 years ago

This is what I get when I try to use this plugin:

TypeError: Cannot read property 'names' of null
    at new Link (/Users/federicozivolo/Progetti/popper-js/node_modules/rollup/src/utils/collapseSourcemaps.js:19:19)
    at /Users/federicozivolo/Progetti/popper-js/node_modules/rollup/src/utils/collapseSourcemaps.js:147:12
    at Array.forEach (native)
    at collapseSourcemaps (/Users/federicozivolo/Progetti/popper-js/node_modules/rollup/src/utils/collapseSourcemaps.js:146:23)
    at Bundle.render (/Users/federicozivolo/Progetti/popper-js/node_modules/rollup/src/Bundle.js:436:11)
    at generate (/Users/federicozivolo/Progetti/popper-js/node_modules/rollup/src/rollup.js:73:28)
    at Object.write (/Users/federicozivolo/Progetti/popper-js/node_modules/rollup/src/rollup.js:102:20)
    at /Users/federicozivolo/Progetti/popper-js/node_modules/rollup/bin/rollup:908:18
    at process._tickCallback (internal/process/next_tick.js:103:7)
    at Module.runMain (module.js:607:11)
FezVrasta commented 7 years ago

Seems like it happens when sourceMap is set to true in Rollup

Comandeer commented 7 years ago

Yes, it's caused by the source maps. I've just pushed the basic support for them to the master, so you can use (or at least try to use…) the plugin straight from GH:

npm install Comandeer/rollup-plugin-babili

However the support for source maps is still very buggy and it'll probably fail on any more complex ES6 code.

FezVrasta commented 7 years ago

Same error with the version from master 😢

FezVrasta commented 7 years ago

This is the branch where I'm trying to use this plugin, maybe it can help.

https://github.com/FezVrasta/popper.js/tree/v1-dev-babili-plus-jsnext

FezVrasta commented 7 years ago

With alpha3 I get:

Cannot read property 'traceSegment' of undefined
TypeError: Cannot read property 'traceSegment' of undefined
    at /Users/federicozivolo/Progetti/popper-js/node_modules/rollup/src/utils/collapseSourcemaps.js:33:26
    at Array.forEach (native)
    at /Users/federicozivolo/Progetti/popper-js/node_modules/rollup/src/utils/collapseSourcemaps.js:31:9
    at Array.map (native)
    at Link.traceMappings (/Users/federicozivolo/Progetti/popper-js/node_modules/rollup/src/utils/collapseSourcemaps.js:28:34)
    at collapseSourcemaps (/Users/federicozivolo/Progetti/popper-js/node_modules/rollup/src/utils/collapseSourcemaps.js:150:60)
    at Bundle.render (/Users/federicozivolo/Progetti/popper-js/node_modules/rollup/src/Bundle.js:436:11)
    at generate (/Users/federicozivolo/Progetti/popper-js/node_modules/rollup/src/rollup.js:73:28)
    at Object.write (/Users/federicozivolo/Progetti/popper-js/node_modules/rollup/src/rollup.js:102:20)
    at /Users/federicozivolo/Progetti/popper-js/node_modules/rollup/bin/rollup:908:18

No idea why the result is different from when I used the GitHub URL...

Comandeer commented 7 years ago

Sorry, I've forgot that I don't have the dist directory on GitHub… I've just published new version of package on npm (version 1.0.0-alpha3). Maybe it would help.

If it still won't work, you could – as a workaround – use Babili in Rollup using rollup-plugin-babel with babili preset in a similar manner as I'm doing at the moment. The only issue with such approach is the fact that Rollup is minifying every file separately, not the whole bundle (and that's why I'm trying to create this plugin).

FezVrasta commented 7 years ago

Thanks for the reply. I'm aware of the other method but I don't like the result. Right now I'm simply running babili via command line to get the best result. If you could fix this plugin it would be so much better tho! 🔥

Comandeer commented 7 years ago

Strangely enough the issue seems to be present only when bundling to the UMD format. When bundling to the ES format, everything is working fine.

Comandeer commented 7 years ago

It seems more like bug in rollup, not the plugin itself. I'll investigate it further.

FezVrasta commented 7 years ago

Thank you, no rush by me. Once the plugin is ready I'll be happy to switch to it tho 🙂

Comandeer commented 7 years ago

I've added simple workaround for it and published in v1.0.0 of plugin. I hope that it will work now.

brianmhunt commented 7 years ago

This still occurs. See e.g. github.com/knockout/tko – running MINIFY=1 rollup -c rollup.config.js results in:

TypeError: Cannot read property 'traceSegment' of undefined at /usr/local/lib/node_modules/rollup/src/utils/collapseSourcemaps.js:33:26 at Array.forEach (native) at /usr/local/lib/node_modules/rollup/src/utils/collapseSourcemaps.js:31:9 at Array.map (native) at Link.traceMappings (/usr/local/lib/node_modules/rollup/src/utils/collapseSourcemaps.js:28:34) at collapseSourcemaps (/usr/local/lib/node_modules/rollup/src/utils/collapseSourcemaps.js:150:60) at Bundle.render (/usr/local/lib/node_modules/rollup/src/Bundle.js:436:11) at generate (/usr/local/lib/node_modules/rollup/src/rollup.js:73:28) at Object.write (/usr/local/lib/node_modules/rollup/src/rollup.js:102:20) at /usr/local/lib/node_modules/rollup/bin/rollup:907:18

Comandeer commented 7 years ago

I cannot reproduce this issue, both with local installation of rollup 0.41.6 and with global one.

What version of rollup do you have installed? Because this issue is reproducible only on <0.41.5.

brianmhunt commented 7 years ago

Thanks, that was indeed the issue!