Closed asasvirtuais closed 3 years ago
I don't think this is a problem with microbundle at all,
debug should probably just point their main export to the node version https://github.com/visionmedia/debug/blob/master/package.json#L54
I will close the issue now, just wanted to leave it here for future devs looking for a solution
Reopening because it was contested
https://github.com/visionmedia/debug/issues/834#issuecomment-901514044
Is there anything @developit can do here?
On my case it's not a problem because I only bundle my own code and keep dependencies imported, but for anyone wanting to really bundle everything, this would likely be an issue.
Is there a reason why you'd be wanting to bundle the debug package? That seems like the kind of dependency that should never be bundled, since it varies by environment.
Looking at the code, this seems like it would be an issue in any Rollup bundle that targets Node. The problem is not that the browser target is being ignored, it's that debug
attempts to differentiate between Node and Electron/NW.js at runtime - that means bundlers have to bundle both the browser and the Node version of debug
if targeting Node (which is bad).
I don't think there's a durable fix that can be implemented in microbundle, since we'd have to inline all 4 conditions from here, 3 of which aren't really knowable at build time:
(eg: someone could be using --target node
for Electron, and this would break that use-case)
Instead, what about aliasing?
microbundle --target node --alias debug=debug/src/node.js
Personally I'd still recommend having debug
be an external dependency instead of bundled. To do that, move it from "dependencies"
to "peerDependencies"
+ "devDependencies"
.
Is there a reason why you'd be wanting to bundle the debug package? That seems like the kind of dependency that should never be bundled since it varies by environment.
I stumbled upon this issue by accident, when some of my internal libraries had nested dependencies I wasn't aware of (which included debug).
To provide context: I bundle my backend code because I run a couple of projects that have a couple of in-house libraries that I manage all by myself, so to avoid having issues arising whenever I update something, I just take a snapshot (bundle) of how the code was like and deploy it, that way I just need to worry about one project at a time.
Personally I'd still recommend having debug be an external dependency instead of bundled. To do that, move it from "dependencies" to "peerDependencies" + "devDependencies".
That is what I did! Thank you for the input! @developit
microbundle bundles of the "debug" package with "--target node" results on ReferenceError: navigator is not defined
https://github.com/icaro-capobianco/debug-microbundle-repro
Workaround is to have debug included as external either through the --external flag or by avoiding unknown dependencies altogether.