close
The Wayback Machine - https://web.archive.org/web/20201206170839/https://github.com/preactjs/wmr/pull/233
Skip to content
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

WMR-229 node builtins #233

Open
wants to merge 2 commits into
base: master
from

Conversation

@dbetteridge
Copy link

@dbetteridge dbetteridge commented Dec 5, 2020

First pass at adding a helpful error message when attempting to use Node built-ins.

Let me know if any changes need making!

Copy link
Member

@developit developit left a comment

Looks good! Reading this I am wondering: would it be more helpful to warn during development but error when building for production? A bunch of the plugins accept a production boolean, and we could have this one use it to fall back to the export default {} shim module during development while emitting this.warn().

dbetteridge added 2 commits Dec 6, 2020
WMR does not polyfill node core modules to prompt users to
double-check their use in the browser and reduce bundle size.

This is a small change to add a thrown error message when this occurs
in production, in development a warning is given instead.
this informs the user which dependency requires the module and where in their code.
Ensure that loading a core module will throw the error we expect.
Uses http as an example.

Ensure outside of production we get a warning instead and a stubbed function.
@dbetteridge dbetteridge force-pushed the dbetteridge:WMR-229-Node-Builtins branch from 2d786f0 to c8b7dd4 Dec 6, 2020
@dbetteridge
Copy link
Author

@dbetteridge dbetteridge commented Dec 6, 2020

Looks good! Reading this I am wondering: would it be more helpful to warn during development but error when building for production? A bunch of the plugins accept a production boolean, and we could have this one use it to fall back to the export default {} shim module during development while emitting this.warn().

Cheers!
I've tacked in a check for a 'production' boolean (which is now passed by the prodBundler) and return a this.warn for test/dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.