Create React App 2.0 brings a year’s worth of improvements in a single dependency update.
We summarized all of the changes in a blog post!
Check it out: Create React App 2.0: Babel 7, Sass, and More.
It provides a high-level overview of new features and improvements. Now let's see how to update your app to the latest version in detail.
Inside any created project that has not been ejected, run:
npm install --save --save-exact [email protected]
or
yarn add --exact [email protected]
If you previously ejected but now want to upgrade, one common solution is to find the commits where you ejected (and any subsequent commits changing the configuration), revert them, upgrade, and later optionally eject again. It’s also possible that the feature you ejected for (maybe Sass or CSS Modules?) is now supported out of the box. You can find a list of notable new features in the Create React App 2.0 blog post.
Like any major release, [email protected]
contains a few breaking changes. We expect that they won't affect every user, but we recommend to scan over these sections to see if something is relevant to you. If we missed something, please file a new issue.
Please upgrade to Node 8 (LTS) or later.
We have dropped default support for Internet Explorer 9, 10, and 11. If you still need to support these browsers, follow the instructions below.
First, install react-app-polyfill
:
npm install react-app-polyfill
or
yarn add react-app-polyfill
Next, place one of the following lines at the very top of src/index.js
:
import 'react-app-polyfill/ie9'; // For IE 9-11 support
import 'react-app-polyfill/ie11'; // For IE 11 support
You can read more about these polyfills here.
Webpack 4 changed the behavior of import()
to be closer in line with the specification.
Previously, importing a CommonJS module did not require you specify the default export. In most cases, this is now required.
If you see errors in your application about ... is not a function
, you likely need to update your dynamic import, e.g.:
const throttle = await import('lodash/throttle');
// replace with
const throttle = await import('lodash/throttle').then(m => m.default);
We previously allowed code splitting with a webpack-specific directive, require.ensure()
. It is now disabled in favor of import()
. To switch to import()
, follow the examples below:
Single Module
require.ensure(['module-a'], function() {
var a = require('module-a');
// ...
});
// Replace with:
import('module-a').then(a => {
// ...
});
Multiple Module
require.ensure(['module-a', 'module-b'], function() {
var a = require('module-a');
var b = require('module-b');
// ...
});
// Replace with:
Promise.all([import('module-a'), import('module-b')]).then(([a, b]) => {
// ...
});
Look at the test
entry in the scripts
section of your package.json
.
Here's a table how to change it from "before" and "after", depending on what you have there:
1.x (if you have this...) | 2.x (...change it to this!) |
---|---|
react-scripts test --env=jsdom |
react-scripts test |
react-scripts test |
react-scripts test --env=node |
To check if action is required, look for the proxy
key in package.json
and follow this table:
- I couldn't find a
proxy
key inpackage.json
- No action is required!
- The value of
proxy
is a string (e.g.http://localhost:5000
)- No action is required!
- The value of
proxy
is an object- Follow the migration instructions below.
It's worth highlighting: if your proxy
field is a string
, e.g. http://localhost:5000
, or you don't have it, skip this section. This feature is still supported and has the same behavior.
If your proxy
is an object, that means you are using the advanced proxy configuration. It has become fully customizable so we removed the limited support for the object-style configuration. Here's how to recreate it.
First, install http-proxy-middleware
using npm or Yarn:
npm install http-proxy-middleware
or
yarn add http-proxy-middleware
Next, create src/setupProxy.js
and place the following contents in it:
const proxy = require('http-proxy-middleware');
module.exports = function(app) {
// ...
};
Now, migrate each entry in your proxy
object one by one, e.g.:
"proxy": {
"/api": {
"target": "http://localhost:5000/"
},
"/*.svg": {
"target": "http://localhost:5000/"
}
}
Place entries into src/setupProxy.js
like so:
const proxy = require('http-proxy-middleware');
module.exports = function(app) {
app.use(proxy('/api', { target: 'http://localhost:5000/' }));
app.use(proxy('/*.svg', { target: 'http://localhost:5000/' }));
};
You can also use completely custom logic there now! This wasn't possible before.
Change the extension of any files in your project using .mjs
to just .js
.
It was removed because of inconsistent support from underlying tools. We will add it back after it stops being experimental, and Jest gets built-in support for it.
Normally, this shouldn't affect your logic and should make the resulting bundle smaller. However, you may be relying on PropTypes definition for production logic. This is not recommended, and will break now. If a library does it, one possible solution is to file an issue in it with a proposal to use a different field (not propTypes
) to signal that the declaration needs to be retained.
This was a large release, and we might have missed something.
Please file an issue and we will try to help.
If you used 2.x alphas, please follow these instructions.
For a readable summary of the changes, check out our blog post.
react-scripts
- #5218 Support globalSetup and globalTeardown Jest options (@gaearon)
- #5073 Add user defined proxy via middleware (@Timer)
- #3945 Allow bundles to be analyzed with Webpack-specific tools (@joshwcomeau)
- #4195 Sass loader (@Fabianopb)
- #3909 Add loader for .graphql files (@petetnt)
- #1288 Create git repository with initial commit (@mauricedb)
- #3718 Import SVGs as React components (#1388) (@iansu)
- #2285 Add support for CSS Modules with explicit filename - [name].module.css (@ro-savage)
- #3804 Support Jest --watchAll flag (@gaearon)
- #3802 Add feature #3116 extended Jest config (@garmeeh)
react-dev-utils
,react-scripts
babel-preset-react-app
- #5047 Allow dynamic import proposal in node_modules (@Timer)
- #3865 feat: add opt-out for prestet-flow to work with @babel/preset-typescript (@oieduardorabelo)
- #3675 add experimental babel-plugin-macros support (@kentcdodds)
babel-preset-react-app
,confusing-browser-globals
,eslint-config-react-app
,react-dev-utils
,react-error-overlay
,react-scripts
- #4077 Webpack 4 (@andriijas)
create-react-app
babel-preset-react-app
,react-scripts
react-app-polyfill
,react-scripts
react-scripts
- #5074 Change default test environment to jsdom (@Timer)
- #5027 Remove
mjs
support (@Timer) - #4009 Update dotenv to 5.0.0 (@iansu)
- #2544 Set the public path to the asset manifest entries (@robinvdvleuten)
- #3884 Don't use app node_modules folder as a resolve fallback (@gaearon)
- #3817 Disable service worker by default (@iansu)
- #2285 Add support for CSS Modules with explicit filename - [name].module.css (@ro-savage)
- #3771 Add preflight check to guard against wrong versions of webpack/eslint/jest higher up the tree (@gaearon)
- #3346 Change the default
start_url
to.
(@evilchuck) - #3419 Remove the navigateFallback behavior from the generated service worker (@jeffposnick)
- #3644 Move browsers to cross-tool config (@ai)
react-dev-utils
babel-preset-react-app
eslint-config-react-app
eslint-config-react-app
,react-error-overlay
,react-scripts
eslint-config-react-app
,react-scripts
- #3121 Redisable require.ensure() (@everdimension)
react-scripts
- #5217 Verify more package versions (@Timer)
- #5214 Fix absolute paths on eject (@gaearon)
- #5212 Don't crash npm test when hg/git are missing (@gaearon)
- #5197 Treat .css and .sass/.scss as side effectful (@gaearon)
- #5196 Format SVG React snapshots as tag with props (@gaearon)
- #5163 Correctly lookup assets when using a relative build directory (@Timer)
- #5151 Toggle
mjs
files tojavascript/auto
type (@Timer) - #5131 Output CSS sourcemaps in separate file (@Timer)
- #5043 Always lint with latest React version (@Timer)
- #5030 Disable webpack chunk coalescing (@Timer)
- #5027 Remove
mjs
support (@Timer) - #4706 Only use safe options when packing CSS assets (@bugzpodder)
- #4562 Configured the thread-loader to keeping workers alive in development mode (@sadkovoy)
- #4318
.mjs
should not resolve before .js files (#4085) (#4317) (@hobochild) - #4419 Map (s?css|sass) modules to identity-obj-proxy in jest (@kusold)
- #4424 ensureSlash: Fix accidental string-to-NaN coercion (@wchargin)
- #4376 Update sass-loader (#4363) (@miraage)
- #4247 Work around Jest environment resolving bug (@gaearon)
- #4234 [next] Revert to use ecma 5 in uglifyOptions (@danielberndt)
- #2544 Set the public path to the asset manifest entries (@robinvdvleuten)
- #3992 Upgrade dotenv-expand to 4.2.0 (#3961) (@iansu)
- #3989 add default value for globPatterns (@viankakrisna)
react-error-overlay
react-dev-utils
babel-preset-react-app
- #5182 Strip flow syntax before any other transform (@Timer)
- #4630 Eliminate regenerator from preset-react-app plugins (@conartist6)
- #5110 Add dynamic import transformer for dependencies in test env (@lixiaoyan)
- #5052 Add Babel config sourceType: 'unambiguous' for dependencies (@lixiaoyan)
- #5046 Correct Babel dependency behavior (@Timer)
- #4248 Enable loose mode for
class-properties
(@rgrochowicz)
babel-preset-react-app
,react-error-overlay
,react-scripts
react-app-polyfill
react-error-overlay
,react-scripts
- #5109 Prevent Babel config overridden (@lixiaoyan)
babel-preset-react-app
,react-scripts
react-dev-utils
,react-error-overlay
,react-scripts
create-react-app
- #4677 Support scoped package names for scripts-version option in create-react-app cli (@bugzpodder)
- #2705 Don't delete error logs when install fails (@mg)
react-dev-utils
,react-scripts
babel-plugin-named-asset-import
,babel-preset-react-app
,eslint-config-react-app
,react-dev-utils
,react-error-overlay
,react-scripts
- #4159 Bump babel-related deps (@existentialism)
create-react-app
,react-dev-utils
,react-scripts
- #3997 Use yarn when running inside yarn workspace. (@bradfordlemley)
create-react-app
,react-scripts
react-dev-utils
,react-scripts
react-dev-utils
- #5150 Run behavioral smoke tests with Jest, add output tests (@Timer)
- #4623 Use yarn build command in predeploy script if using yarn (@alexbrazier)
- #4470 Adjust browser defaults (@Timer)
- #4001 Add support for new yarn workspaces config format (@detrohutt)
- #3980 Autodetect GoLand editor (@ifedyukin)
- #3808 Use wmic to get process list on Windows (@levrik)
react-scripts
- #4169 Workbox service worker (@davejm)
- #5096 Disable source maps for node_modules (@Timer)
- #4716 add postcss-preset-env, remove autoprefixer (@heygrady)
- #1457 Add eslintConfig to new projects automatically (@lifeiscontent)
- #5030 Disable webpack chunk coalescing (@Timer)
- #4582 Added thread-loader tweak for application code entry-point (@sadkovoy)
- #4562 Configured the thread-loader to keeping workers alive in development mode (@sadkovoy)
- #4504 webpack 4 scope hoisting (@bugzpodder)
- #4461 Update svgr (@iansu)
- #3867 Provide callbacks in serviceWorker (next) (@piotr-cz)
- #3235 Applies new theme and adds docs link to template (@lukejacksonn)
- #3512 Enhance Jest config error for
setupTestFrameworkScriptFile
(@jackfranklin) - #3778 Compile code in parallel (@Timer)
- #3771 Add preflight check to guard against wrong versions of webpack/eslint/jest higher up the tree (@gaearon)
- #3618 use uglifyjs-webpack-plugin v1 (@viankakrisna)
babel-preset-react-app
,react-error-overlay
,react-scripts
react-dev-utils
,react-error-overlay
,react-scripts
- #4930 Switch from cheap-module-source-map eval-source-map (@jasonLaster)
- #3124 update jest to 22 and support watchPathIgnorePatterns configuration (@aisensiy)
confusing-browser-globals
,react-dev-utils
,react-error-overlay
,react-scripts
- #4846 Update jest version (@skoging)
- #4362 Bumped jest version to 22.4.1 (@CGreenburg)
babel-preset-react-app
,confusing-browser-globals
,eslint-config-react-app
,react-dev-utils
,react-error-overlay
,react-scripts
- #4077 Webpack 4 (@andriijas)
babel-preset-react-app
- #4432 Update babel-plugin-macros to fix a bug (@stereobooster)
- #3818 Remove PropTypes from production build (#209) (@iansu)
create-react-app
- #4375 fix: update envinfo + implementation, update issue_template (@tabrindle)
eslint-config-react-app
,react-error-overlay
,react-scripts
eslint-config-react-app
- #3844 remove radix eslint rule (@sendilkumarn)
create-react-app
,react-dev-utils
,react-scripts
babel-preset-react-app
,create-react-app
,react-dev-utils
,react-error-overlay
,react-scripts
babel-preset-react-app
,react-scripts
babel-preset-react-app
,eslint-config-react-app
,react-dev-utils
,react-error-overlay
,react-scripts
react-scripts
- #5211 Adds instructions to README on how to customize Bootstrap with Sass (@mslooten)
- #5147 Document adding SVGs as React components (@mareksuscak)
- #5193 Fix typo in 'Configuring the Proxy Manually' (@fabriziocucci)
- #5111 Updates to README to reflect Workbox usage. (@jeffposnick)
- #5169 Add additional troubleshooting for Github Pages (@dwang)
- #5145 Mention .module.scss/sass convention (@mareksuscak)
- #5105 as per #5104 (@sag1v)
- #5071 Update usage advice of husky to 1.0 (@martinlechner1)
- #5077 small typo fix (@tteltrab)
- #5070 Integrating with an API Backend: add API Platform (@dunglas)
- #5064 fix minor typo in troubleshooting github pages (@kaznovac)
- #5035 Remove paywalled tutorial link for Storybook (@imgntn)
- #3924 Updates to reflect service worker registration being opt-in. (@jeffposnick)
- #4881 flowtype.org -> flow.org (@web2033)
- #4825 Update support info for service workers (@j-f1)
- #4738 Fix typo (@mjw56)
- #4741 remove extra dot on devtool link comment (@shelldandy)
- #4703 Suggest
reactstrap
instead ofreact-bootstrap
(@zx6658) - #4566 Move whitespace comment closer to where it applies (@mgedmin)
- #4497 [Read Me template patch] Warn about #871 until it's actually fixed. (@saimonmoore)
- #4205 Chokidar Updates (@originell)
- #4286 Fix some typos in README.md (@apaatsio)
- #4298 Added learnstorybook.com to Storybook links (@tmeasday)
- #4117 Document multiple build environments via
env-cmd
#4071 (@jMuzsik) - #4197 Add troubleshooting for Github Pages (@xnt)
- #4236 use the lastest url of gitignore file (@Plortinus)
- #4239 Fix typo in comment and be clearer about
ecma
settings in uglifyjs options (@danielberndt) - #4164 Fix typos in example monorepo documentation. (@bradfordlemley)
- #4089 Fix a typo in packages/react-scripts/template/README.md (@nott)
- #4101 Docs: Update status of Object Rest/Spread proposal (@jpaquim)
- #4107 docs: use node_js 8 in example travis.yml (@nikolas2)
- #3821 Updated react-scripts Readme.md to better document GitHub Pages (@EdwaRen)
- Other
- #5102 Fix Troubleshooting link (@gdi2290)
- #4551 Update targeted IE version in documentation (@antzshrek)
- #4814 Update CODE_OF_CONDUCT.md (@Ashleyotero)
- #4638 Add instructions on alternative methods of app creation (@RusinovAnton)
- #4546 Update file tree view (@antzshrek)
- #4449 add create-react-app-parcel to Alternatives section in README (@sw-yx)
- #4294 documentation: added License to the README.md (@thiagopaiva99)
- #4323 Fix typo in e2e-simple.sh comment (@bmuenzenmeyer)
- #4134 fix: Minor typos (@fejes713)
- #4114 Update CONTRIBUTING.md (@jkzing)
- #3825 Add svg rendering for error example (@marionebl)
- #3810 Update screencast to use npx (@marionebl)
create-react-app
- #4309 Fix typo to word bootstrapped in condition to check for old version o… (@jamesvsshark)
- #4015 add
create-react-app --help
info for local file path--scripts-version
support (@albertstill)
react-dev-utils
,react-scripts
eslint-config-react-app
babel-plugin-named-asset-import
,babel-preset-react-app
,confusing-browser-globals
,create-react-app
,eslint-config-react-app
,react-app-polyfill
,react-dev-utils
,react-error-overlay
,react-scripts
- Other
- #5183 Test class properties (@Timer)
- #5146 Add behavior e2e tests (@Timer)
- #4774 [internal] Use Yarn cache for travis (@bugzpodder)
- #4626 [internal] Fix node 10 test issue (@bugzpodder)
- #3816 Automate screencast recordings (@marionebl)
react-scripts
- #5180 Fetch Workbox from CDN (@Timer)
- #5170 Remove thread-loader (@Timer)
- #5157 Forwards args through thread-loader (@arcanis)
- #5085 Remove highlightCode:true because it's now the default (@marcofugaro)
- #5098 [internal] remove babelrc dependency for kitchensink test (@bugzpodder)
- #5076 Revert "Add loader for .graphql files (#3909)" (@Timer)
- #5062 Upgrade svgr to v2 and disable Prettier & SVGO (@Timer)
- #5059 Switch back to cheap-module-source-map (@jasonLaster)
- #4891 Move favicon.ico to accommodate Chrome (@thejohnfreeman)
- #5053 Normalize babel caching across the board (@Timer)
- #4550 Jest 23 and tests (@bugzpodder)
- #5043 Always lint with latest React version (@Timer)
- #4955 Update webpack-dev-server 3.1.5 → 3.1.7 (@addaleax)
- #4776 Bump babel-loader to fix npm warning (@frenzzy)
- #4767 [internal] Separate out kitchensink test into two (@bugzpodder)
- #4014 enable manifest plugin on dev (@viankakrisna)
- #4435 Update paths.js, rename shadow path variable (@graemecode)
- #4331 Bump
fsevents
. (@wtgtybhertgeghgtwtg) - #4174 Yarn workspace transpilation verification. (@bradfordlemley)
- #3842 fix small grammatical typo in webpack config documentation (@andrewerrico)
react-dev-utils
babel-preset-react-app
,react-error-overlay
,react-scripts
babel-preset-react-app
- #5119 Clean up @babel/plugin-transform-regenerator (@lixiaoyan)
- #5033 Lock babel configuration back to IE 9 support (ES5) (@Timer)
react-dev-utils
,react-scripts
babel-preset-react-app
,create-react-app
,react-dev-utils
,react-error-overlay
,react-scripts
react-error-overlay
,react-scripts
- #5050 Eslint 5.6 (@bugzpodder)
babel-plugin-named-asset-import
,babel-preset-react-app
,react-dev-utils
,react-error-overlay
,react-scripts
- #5042 Upgrade to Babel 7 stable (@Timer)
- #4253 Upgrade Babel to
beta.44
(@andriijas)
confusing-browser-globals
,react-dev-utils
,react-error-overlay
,react-scripts
react-dev-utils
,react-error-overlay
,react-scripts
create-react-app
react-error-overlay
- #4211 Revert lint-related changes made in #4193 (@NMinhNguyen)
- #4193 Minor fixes to CI (@ro-savage)
confusing-browser-globals
,eslint-config-react-app
eslint-config-react-app
,react-scripts
- #3723 Updating ESlint to ^4.15.0 and adding new rules to config (@chrislaughlin)
- A.J. Roberts (@detrohutt)
- Aaron Reisman (@lifeiscontent)
- Ade Viankakrisna Fadlil (@viankakrisna)
- Albert Still (@albertstill)
- Alex Brazier (@alexbrazier)
- Andreas Cederström (@andriijas)
- Andrew (@andrewerrico)
- Andrew Clark (@acdlite)
- Andrew Ho (@andrwh)
- Andrey Sitnik (@ai)
- Anna Henningsen (@addaleax)
- Anton Rusinov (@RusinovAnton)
- Antti Ahti (@apaatsio)
- Ashley Otero (@Ashleyotero)
- Bond (@bondz)
- Bradford Lemley (@bradfordlemley)
- Brian Muenzenmeyer (@bmuenzenmeyer)
- Brian Ng (@existentialism)
- Chad Greenburg (@CGreenburg)
- Chris Laughlin (@chrislaughlin)
- Clement Hoang (@clemmy)
- Conrad Buck (@conartist6)
- Craig Mulligan (@hobochild)
- Dan Abramov (@gaearon)
- Daniel (@danielberndt)
- Daniel Wang (@dwang)
- David Moodie (@davejm)
- Dmitriy Sadkovoy (@sadkovoy)
- Eduardo Rabelo (@oieduardorabelo)
- Edward Ren (Eddie) (@EdwaRen)
- Ernesto García (@gnapse)
- Eugene Kopich (@web2033)
- Fabiano Brito (@Fabianopb)
- Fabrizio Cucci (@fabriziocucci)
- Fredrik Palmquist (@fiddep)
- Futa Ogawa (@ogawa0071)
- Gary Meehan (@garmeeh)
- Gonzalo Pozzo (@goncy)
- Grady Kuhnline (@heygrady)
- Graeme (@graemecode)
- Harry Moreno (@morenoh149)
- Ian Sutherland (@iansu)
- Ideveloper (@zx6658)
- Igor Fedyukin (@ifedyukin)
- Irvin Denzel Torcuato (@identor)
- JK (@jkzing)
- Jack Franklin (@jackfranklin)
- Jack Zhao (@bugzpodder)
- James B. Pollack (@imgntn)
- James Simoes (@jamesvsshark)
- Jason Laster (@jasonLaster)
- Jed Fox (@j-f1)
- Jeffrey Posnick (@jeffposnick)
- Jerry (@jMuzsik)
- Jih-Chi Lee (@jihchi)
- Joe Haddad (@Timer)
- Joel George V (@joelgeorgev)
- John Freeman (@thejohnfreeman)
- Joshua Comeau (@joshwcomeau)
- João Paquim (@jpaquim)
- Kent C. Dodds (@kentcdodds)
- Kévin Dunglas (@dunglas)
- Levin Rickert (@levrik)
- Luis Nell (@originell)
- Luke Jackson (@lukejacksonn)
- Maciej Kasprzyk (@maciej-ka)
- Magnús Örn Gylfason (@mg)
- Marco Fugaro (@marcofugaro)
- Marco Slooten (@mslooten)
- Marek Suscak (@mareksuscak)
- Mario Nebl (@marionebl)
- Marius Gedminas (@mgedmin)
- Marko Kaznovac (@kaznovac)
- Martin Lechner (@martinlechner1)
- Maurice de Beijer (@mauricedb)
- Maël Nison (@arcanis)
- Michaël De Boey (@MichaelDeBoey)
- Miguel Palau (@shelldandy)
- Mike Kusold (@kusold)
- Mike Wilcox (@mjw56)
- Mikhail Osher (@miraage)
- Minh Nguyen (@NMinhNguyen)
- Nick Bartlett (@tteltrab)
- PatrickJS (@gdi2290)
- Pete Nykänen (@petetnt)
- Piotr (@piotr-cz)
- Rami (@evilchuck)
- Reuben Antz (@antzshrek)
- Ro Savage (@ro-savage)
- Rob Grochowicz (@rgrochowicz)
- Robin van der Vleuten (@robinvdvleuten)
- Sagiv ben giat (@sag1v)
- Saimon Moore (@saimonmoore)
- Sendil Kumar N (@sendilkumarn)
- Siddharth Doshi (@sidoshi)
- Stas Rudakou (@nott)
- Stefan Feješ (@fejes713)
- Thiago Galvani (@thiagopaiva99)
- Tom Coleman (@tmeasday)
- Tore Hammervoll (@skoging)
- Trevor Brindle (@tabrindle)
- Vicente Plata (@xnt)
- Victor Amupitan (@amupitan)
- Viktor Havrylin (@Fer0x)
- Vladimir Kutepov (@frenzzy)
- William Chargin (@wchargin)
- XiaoYan Li (@lixiaoyan)
- @Plortinus
- @arianon
- @everdimension
- @nikolas2
- @stereobooster
- @wtgtybhertgeghgtwtg
- aisensiy (@aisensiy)
- froyog (@froyog)
- shawn wang (@sw-yx)
Please refer to CHANGELOG-1.x.md for earlier versions.