The error code system substitutes React's invariant error messages with error IDs to provide a better debugging support in production. Check out the blog post here.
- For each release, we run
yarn build -- --extract-errors
to update the error codes before callingyarn build
. The build step usescodes.json
for a production (minified) build; there should be no warning likeError message "foo" cannot be found
for a successful release. - The updated
codes.json
file should be synced back to the master branch. The error decoder page in our documentation site usescodes.json
from master; if the json file has been updated, the docs site should also be rebuilt (rake copy_error_codes
is included in the defaultrake release
task). - Be certain to run
yarn build -- --extract-errors
directly in the release branch (if not master) to ensure the correct error codes are generated. These error messages might be changed/removed before cutting a new release, and we don't want to add intermediate/temporary error messages tocodes.json
. However, if a PR changes an existing error message and there's a specific production test (which is rare), it's ok to updatecodes.json
for that. Please useyarn build -- --extract-errors
and don't edit the file manually.
The error code system consists of 5 parts:
codes.json
contains the mapping from IDs to error messages. This file is generated by the Gulp plugin and is used by both the Babel plugin and the error decoder page in our documentation. This file is append-only, which means an existing code in the file will never be changed/removed.extract-errors.js
is an node script that traverses our codebase and updatescodes.json
. Use it by callingyarn build -- --extract-errors
.replace-invariant-error-codes.js
is a Babel pass that rewrites error messages to IDs for a production (minified) build.reactProdInvariant.js
is the replacement forinvariant
in production. This file gets imported by the Babel plugin and should not be used manually.ErrorDecoderComponent
is a React component that lives at https://reactjs.org/docs/error-decoder.html. This page takes parameters like?invariant=109&args[]=Foo
and displays a corresponding error message. Our documentation site'sRakefile
has a task (bundle exec rake copy_error_codes
) for adding the latestcodes.json
to the error decoder page. This task is included in the defaultbundle exec rake release
task.