Skip to content

Last call for Create React App v2 #5103

Closed
@Timer

Description

@Timer
Contributor

Hi everyone! We just released what we hope to be the last beta before v2 is marked stable and tagged latest on npm tomorrow.

Please try it as soon as possible and let us know if you run into any issues!

Create new application:

$ npx create-react-app@next --scripts-version=@next test-next

Upgrade existing:

$ npm install react-scripts@next --save
$ # or
$ yarn add react-scripts@next

Here's a draft of the release notes:

Create React App v2.0.1

New Features

  1. Updated tooling: Babel 7, webpack 4, Jest 23
  2. Packages using new JavaScript features in node_modules now work
  3. Automatic vendor bundles and long term caching
  4. CSS Modules
  5. Sass Support
  6. SVGs as React Components
  7. Babel Macros
  8. Targetable CSS support, with automatic polyfills and prefixing

Migrating from 1.1.15 to 2.0.1

Inside any created project that has not been ejected, run:

$ npm install --save --save-exact react-scripts@2.0.1
$ # or
$ yarn add --exact react-scripts@2.0.1

Next, follow the migration instructions below that are relevant to you.

You may no longer code split with require.ensure()

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]) => {
  // ...
});

The default Jest environment was changed to jsdom

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

.mjs file extension support was removed

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.

Move advanced proxy configuration to src/setupProxy.js

This change is only required for individuals who used the advanced proxy configuration in v1.

To check if action is required, look for the proxy key in package.json. Then, follow the table below.

  1. I couldn't find a proxy key in package.json
    • No action is required!
  2. The value of proxy is a string (e.g. http://localhost:5000)
    • No action is required!
  3. The value of proxy is an object
    • Follow the migration instructions below.

If your proxy is an object, that means you are using the advanced proxy configuration.

Again, if your proxy field is a string, e.g. http://localhost:5000, you do not need to do anything. This feature is still supported and has the same behavior.

First, install http-proxy-middleware using npm or Yarn:

$ npm install http-proxy-middleware --save
$ # 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.

Internet Explorer is no longer supported by default (but you can opt in!)

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 --save
$ # 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.

The behavior of a CommonJS import() has changed

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);

Anything missing?

This was a large release, and we might have missed something.

Please file an issue and we will try to help.

Migrating from 2.0.0-next.xyz

If you used 2.x alphas, please follow these instructions.

Detailed Changelog

>> TODO <<

Activity

added this to the 2.0.0 milestone on Sep 26, 2018
changed the title [-]Last call for `react-scripts` v2[/-] [+]Last call for Create React App v2[/+] on Sep 26, 2018
zaguiini

zaguiini commented on Sep 26, 2018

@zaguiini

I'm a bit late to the party. What do you mean with "node_modules are now compiled"?

gaearon

gaearon commented on Sep 26, 2018

@gaearon
Contributor

I reworded to

Packages using new JavaScript features in node_modules now work

Does this make more sense?

ozzie1998

ozzie1998 commented on Sep 26, 2018

@ozzie1998

I'm a bit late to the party. What dou you mean with "node_modules are now compiled"?

node_modules bundled with the app?

jordyvandomselaar

jordyvandomselaar commented on Sep 26, 2018

@jordyvandomselaar

Thanks @gaearon, I was about to ask the same thing ^.^

I don't think I've ever needed it, but I guess it's nice it's there. Maybe this'll help build proper "goto definition" functionality, right now it keeps jumping to compiled js, and it's a mess.

zaguiini

zaguiini commented on Sep 26, 2018

@zaguiini

Does this make more sense?

Yes. Thanks Dan!

gaearon

gaearon commented on Sep 26, 2018

@gaearon
Contributor

I don't think I've ever needed it, but I guess it's nice it's there. Maybe this'll help build proper "goto definition" functionality, right now it keeps jumping to compiled js, and it's a mess.

I think there is some kind of misunderstanding here.

Previously, if somebody published a package that used newer syntax like const, and you imported that package, your app wouldn't build. We've had dozens of issues filed about this. See all issues linked from #1125. Now it will work.

dmythro

dmythro commented on Sep 26, 2018

@dmythro

Have an issue with @next:

When specified, "proxy" in package.json must be a string.
Instead, the type of "proxy" was "object".
Either remove "proxy" from package.json, or make it a string.

Actually, there was pretty extensive amount of options for proxy, are they all gone? With target, pathRewrite etc.
I used them on alpha as well.

Timer

Timer commented on Sep 26, 2018

@Timer
ContributorAuthor

@Z-AX this is not a bug -- we removed the proxy options. Please read the migration instructions above. 😄

andriijas

andriijas commented on Sep 26, 2018

@andriijas
Contributor

Good job everyone working on wrapping up the 2.0 release! Thanks for your efforts!

165 remaining items

gaearon

gaearon commented on Oct 1, 2018

@gaearon
Contributor

Sorry, that sounds like a Yarn failure so we can't help with it.

pimlottc-gov

pimlottc-gov commented on Oct 1, 2018

@pimlottc-gov

@gaearon okay, I mention it though because I didn't have this issue before I upgraded react-scripts.

JeffBaumgardt

JeffBaumgardt commented on Oct 1, 2018

@JeffBaumgardt

Looks like there is a new release of eslint@5.6.1 that CRA is complaining about if you have eslint installed local.

gaearon

gaearon commented on Oct 1, 2018

@gaearon
Contributor

I mean, in general we never supported installing eslint at top level of your project.

JeffBaumgardt

JeffBaumgardt commented on Oct 1, 2018

@JeffBaumgardt

I mean, in general we never supported installing eslint at top level of your project.

I know this is the official stance and this discussion should take place elsewhere but I think many people who are using CRA in a production / semi-production setup use eslint to do more than in editor linting tasks.

gaearon

gaearon commented on Oct 1, 2018

@gaearon
Contributor

I understand where you're coming from — I'm not saying we're opposed on principle but I'm saying that it has always caused hard-to-debug issues like this due to how ESLint doesn't allow presets to encapsulate their plugins. ESLint plans to fix this in ESLint 5 so that will solve the issue permanently. In the meantime, we want to warn our users that when they do something like this, our setup can break.

Again, you can ignore our warning, just as the warning says. Or maybe we're talking about different things. Did you notice the warning provides instructions for how to turn it off at the bottom?

gaearon

gaearon commented on Oct 2, 2018

@gaearon
Contributor
R4z1ell

R4z1ell commented on Oct 13, 2018

@R4z1ell

I've followed the instructions from the proxy migrations but they don't work for me, i've installed the
'http-proxy-middleware' package and created the 'setupProxy.js' file inside the 'src' folder in my client but
it's not working, any idea?

gaearon

gaearon commented on Oct 13, 2018

@gaearon
Contributor

@R4z1ell Please file a new issue.

locked as resolved and limited conversation to collaborators on Oct 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @weyert@gnapse@ai@ligaz@andriijas

        Issue actions

          Last call for Create React App v2 · Issue #5103 · facebook/create-react-app