Skip to content

Commit f1e5eb3

Browse files
authored
Clarify the npm precompilation advice
It's confusing: https://mobile.twitter.com/brianleroux/status/923581596720013312 h/t @brianleroux
1 parent 0549f02 commit f1e5eb3

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

template/README.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -2186,14 +2186,20 @@ This will only work for locales that have been explicitly imported before.
21862186

21872187
### `npm run build` fails to minify
21882188

2189-
You may occasionally find a package you depend on needs compiled or ships code for a non-browser environment.<br>
2190-
This is considered poor practice in the ecosystem and does not have an escape hatch in Create React App.<br>
2189+
Some third-party packages don't compile their code to ES5 before publishing to npm. This often causes problems in the ecosystem because neither browsers (except for most modern versions) nor some tools currently support all ES6 features. We recommend to publish code on npm as ES5 at least for a few more years.
2190+
21912191
<br>
21922192
To resolve this:
2193-
1. Open an issue on the dependency's issue tracker and ask that the package be published pre-compiled (retaining ES6 Modules).
2194-
2. Fork the package and publish a corrected version yourself.
2193+
2194+
1. Open an issue on the dependency's issue tracker and ask that the package be published pre-compiled.
2195+
* Note: Create React App can consume both CommonJS and ES modules. For Node.js compatibility, it is recommended that the main entry point is CommonJS. However, they can optionally provide an ES module entry point with the `module` field in `package.json`. Note that **even if a library provides an ES Modules version, it should still precompile other ES6 features to ES5 if it intends to support older browsers**.
2196+
2197+
2. Fork the package and publish a corrected version yourself.
2198+
21952199
3. If the dependency is small enough, copy it to your `src/` folder and treat it as application code.
21962200

2201+
In the future, we might start automatically compiling incompatible third-party modules, but it is not currently supported. This approach would also slow down the production builds.
2202+
21972203
## Something Missing?
21982204

21992205
If you have ideas for more “How To” recipes that should be on this page, [let us know](https://github.com/facebookincubator/create-react-app/issues) or [contribute some!](https://github.com/facebookincubator/create-react-app/edit/master/packages/react-scripts/template/README.md)

0 commit comments

Comments
 (0)