Skip to content

Instantly share code, notes, and snippets.

@iansu
Last active April 5, 2022 17:21
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save iansu/4fab7a9bfa5fa6ebc87a908c62f5340b to your computer and use it in GitHub Desktop.
Save iansu/4fab7a9bfa5fa6ebc87a908c62f5340b to your computer and use it in GitHub Desktop.
Using React 17 and the new JSX transform with Create React App 4.0 Alpha

Using React 17 and the new JSX transform with Create React App 4.0 Alpha

Create React App 4.0 is currently in alpha and supports using React 17 and the new JSX transform. To use it, follow these instructions.

Create a new app

Create a new app with npx create-react-app@next --scripts-version=@next --template=cra-template@next my-js-app

Update to React 17

Edit package.json in the new app and change the version numbers for react and react-dom to 17.0.0-rc.2 (the latest version of React 17 at the time of this writing). The updated versions should look like this:

  "react": "^17.0.0-rc.2",
  "react-dom": "^17.0.0-rc.2",

Disable ESLint rules

Create React App's current ESLint configuration will warn you when using JSX without importing React. You can disable these rules by updating the eslintConfig section in package.json. The updated config should look like this:

  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ],
    "rules": {
      "react/jsx-uses-react": "off",
      "react/react-in-jsx-scope": "off"
    }
  },

Save your changes to package.json and run either npm install or yarn.

Remove React imports

Open src/App.js and delete the line import React from 'react' from the top of the file. Start your app (with either npm run start or yarn start) and everything should continue to work, even though you're no longer importing React!

Resources

For more information about the new JSX transform in React 17 see the post from the React Blog and the Babel release announcement.

@alissonmbr
Copy link

Webpack 5 is coming soon, is current in v5.0.0-rc.3. There is plan to use webpack 5 on create-react-app 4? And also has plans to use webpack 5 Module Federation without ejecting?

@hongbo-miao
Copy link

Thanks for the upgrading guide. Will give it a try!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment