-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
V5 add back support for node builtins #11764
Changes from 7 commits
166d872
5e83115
944a50a
cb4a8a3
e6b5b3a
46b4e0c
17fa022
20dada7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,66 @@ | ||||||||||||
--- | ||||||||||||
id: nodejs-builtin-fallbacks | ||||||||||||
title: NodeJS builtin fallbacks | ||||||||||||
--- | ||||||||||||
|
||||||||||||
NodeJS builtin fallbacks enable you to import NodeJS builtin modules meant for Node and fallback to browser specific modules in your web application. | ||||||||||||
|
||||||||||||
Per default Create React App set fallbacks to empty modules in production build and development fallbacks in development mode. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did some light copy edits. but this sentence isn't very clear, could you clarify what you mean by 'empty modules' and 'development fallbacks'? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think this is how the sentence was intended, connecting to the previous sentence. I changed the inclusion to past tense. |
||||||||||||
|
||||||||||||
In development mode you might get error messages in your browser console similar to: | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
i'm seeing the errors in my terminal where i'm running |
||||||||||||
|
||||||||||||
``` | ||||||||||||
(dev) Error: Module "path" not found, cannot access property "join", please read https://create-react-app.dev/docs/nodejs-builtin-fallbacks | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this appears to be a broken link |
||||||||||||
``` | ||||||||||||
|
||||||||||||
_(It's possible to disable these warnings in development using the environment variable: `DISABLE_MISSING_NODEJS_BUILTIN_MODULE_FALLBACK_WARNING=true`)_ | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
**IMPORTANT:** Before fixing this dependency, please make sure to only use Npm packages meant for the browser and not for Node / backend. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
It takes abit of work but visit the project documentation, README.md and if on GitHub etc. look open and closed issues in the project e.g. search "browser" to see if maintainers close issues for browser support. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
i don't think this is necessary |
||||||||||||
|
||||||||||||
Implications of loading packages not build for the browser can vary from security, bundle size etc. - There might be better alternatives. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
**Escape hatch** | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
To fix the issue you will need to add the browser fallback - the example above complains about missing `path` module. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
```bash | ||||||||||||
npm install path-browserif | ||||||||||||
# or.. | ||||||||||||
yarn add path-browserif | ||||||||||||
``` | ||||||||||||
|
||||||||||||
Create React App will recognize the fallback and use that instead of an empty module. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
removing b/c covered in the previous suggestion |
||||||||||||
_(Find the fallback package in the table bellow)_ | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
| NodeJS builtin module | Browser version | | ||||||||||||
| :-------------------- | :------------------------- | | ||||||||||||
| assert | assert | | ||||||||||||
| buffer | buffer | | ||||||||||||
| console | console-browserif | | ||||||||||||
| constants | constants-browserif | | ||||||||||||
| crypto | crypto-browserif | | ||||||||||||
| domain | domain-browse | | ||||||||||||
| events | events | | ||||||||||||
| http | stream-htt | | ||||||||||||
| https | https-browserif | | ||||||||||||
| os | os-browserify/browse | | ||||||||||||
| path | path-browserif | | ||||||||||||
| punycode | punycode | | ||||||||||||
| process | process/browse | | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least half the names in the 2nd column seem to be missing their last letter:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're looking at this at the moment, and just noticed this issue too. Thanks @no23reason and @PjotrB. |
||||||||||||
| querystring | querystring-es | | ||||||||||||
| stream | stream-browserif | | ||||||||||||
| stream_duplex | readable-stream/duple | | ||||||||||||
| stream_passthrough | readable-stream/passthroug | | ||||||||||||
| stream_readable | readable-stream/readabl | | ||||||||||||
| stream_transform | readable-stream/transfor | | ||||||||||||
| stream_writable | readable-stream/writabl | | ||||||||||||
| string_decoder | string_decoder | | ||||||||||||
| sys | util | | ||||||||||||
| timers | timers-browserif | | ||||||||||||
| tty | tty-browserif | | ||||||||||||
| url | url | | ||||||||||||
| util | util | | ||||||||||||
| vm | vm-browserif | | ||||||||||||
| zlib | browserify-zlib | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.