-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core): require('debug') throws exception in browser #1237
Conversation
Remove 'require()' call from debug.js because it breaks es builds in browser via rollup.js Fixes it
Hm, this will bundle the Which is removed with dead code elimination, so it isn't bundled server side, in production, nor tests. The current change will always import the module and bundle it in systems that do not make use of tree shaking. We'll need to find a solution that does not bundle it in either case. Not sure on this one yet. |
Current coverage is 95.89% (diff: 100%)@@ master #1237 diff @@
==========================================
Files 880 880
Lines 4901 4901
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
Hits 4700 4700
Misses 201 201
Partials 0 0
|
Could you better define "breaks it" for me here? I'd like to find a solution that works regardless of the build tool a user chooses. |
"breaks it" i.e. 'require('debug') throws exception in the browser' This is an interruption of normal program execution. require(...) is not a part of es6, I believe it's a function from a runtime module loader that browsers do not natively support. The es6 build is for es6 modules, and the imports are unfortunately top-level and not determined at runtime, as that's how the language is these days... The repro would be to use the module in an es6 browser environment without the webpack loader. Like I did with rollup. |
OK, I see the issue now, thanks. I'll have to find a solution to this that does not include the import statement for Goals are:
I have a couple ideas, others welcome. I'll come back to this one when I have time. |
I've performed some tests there. Rollup doesn't support My proposal is move debug to separate package which will have ES version without conditional import and CJS version with require. Also, it's single place where we use |
Update on my thoughts here. We currently use the We could use something like https://github.com/codemix/babel-plugin-trace for these logs instead. We could then entirely remove these statements automatically in our builds. There is also https://github.com/GavinJoyce/babel-plugin-remove-functions which would allow us to target individual functions for removal. This also would enable us to keep the existing |
Closing in favor of #1663. |
Remove 'require()' call from debug.js because it breaks es builds in browser via rollup.js
Fixes it