cramforce / splittable

Module bundler with support for code splitting, ES6 & CommonJS modules.
Apache License 2.0
945 stars 34 forks source link

Issues with Commonly Used NPM Packages #46

Closed danbucholtz closed 7 years ago

danbucholtz commented 7 years ago

https://github.com/danbucholtz/splittable-node-uuid run npm install, npm run build-and-bundle and then spin up an http server of choice. Open index.html

This super simple example repo shows an issue with importing a popular library that uses browserify crypto. The library in question is node-uuid, 6M downloads in the past month.

When I try to bundle, I receive an issue about Error: Only masking of entire modules via false supported in package.json#browser:0 [/Users/dan/Desktop/sample-project/node_modules/randombytes.package.json]. When I look at this section of the code, I am unclear on what's going on. What is the purpose of looking at the package.json browser key character by character? What is the intend of this section of the code?

If I remove that section of the code, I am able to progress further in the bundling process, but I am met with a circular dependency.

Node node_modules/readable-stream/lib/_stream_duplex.js forms circular dependency: node_modules/readable-stream/lib/_stream_transform.js -> node_modules/readable-stream/lib/_stream_duplex.js -> node_modules/readable-stream/lib/_stream_readable.js -> node_modules/readable-stream/lib/_stream_duplex.js

How does closure compiler handle circular dependencies? I know browserify and webpack can figure these things out, but Rollup has major issues with them. Is there anything we can do to mitigate these issues?

The Ionic Framework team are considering making Splittable a first class citizen in Ionic so hundreds of thousands of users could potentially start using it in the coming months. We don't know enough about Closure Compiler to know if that is a good idea or not. We'd love to hear your opinion on the topic.

Thanks, Dan

cramforce commented 7 years ago

Basically the way things work in closure compiler there is no chance to support it. It would be possible without splitting, but with more than 1 bundle, one cannot decide into which bundle a dep should go.

It is always possible to work around circular deps, by making them application layer: Where you have a dep that has a getter and setter to provide a particular dep. The application makes sure that the setter is always called before anything actually uses the dependency. It does, however, require changing the downstream dependency in this fashion. Does this make sense?

danbucholtz commented 7 years ago

@cramforce,

Any chance you're in the Angular slack? I would love to chat for a bit just to pick your brain on splittable. Last week my Ionic colleagues and I were in Mountain View with the Angular team and had a small hackathon with the Closure Compiler team. We would love to set-up a quick meeting to learn more about Closure and some of the splittable code as we're struggling a bit.

Please let me know if available or interested. My email is dan.b at ionic dot io.

Thanks, Dan

cramforce commented 7 years ago

Definitely not on the Angular slack and little interest to join more slacks :)

But feel free to join https://github.com/ampproject/amphtml/blob/master/DEVELOPING.md#slack-and-mailing-list I hang out there a lot. Does that work? Otherwise email is fine.

danbucholtz commented 7 years ago

Will do. I'll contact you.

Thanks! Dan