create-react-app: Build fails after eject: Cannot find module '@babel/plugin-transform-react-jsx'

Is this a bug report?

Yes

Environment

Environment Info:

  System:
    OS: Linux 4.18 Fedora 29 (Workstation Edition) 29 (Workstation Edition)
    CPU: x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
  Binaries:
    Node: 10.13.0 - /usr/bin/node
    Yarn: 1.12.3 - ~/.npm-packages/bin/yarn
    npm: 6.4.1 - /usr/bin/npm
  Browsers:
    Chrome: 70.0.3538.102
    Firefox: 63.0.1
  npmPackages:
    react: ^16.7.0 => 16.7.0 
    react-dom: ^16.7.0 => 16.7.0 
    react-scripts: Not Found
  npmGlobalPackages:
    create-react-app: Not Found

Steps to Reproduce

  1. npx create-react-app project
  2. cd project
  3. yarn eject
  4. yarn build

Expected Behavior

Build success.

Actual Behavior

Build fails.

Creating an optimized production build...
Failed to compile.

./src/index.js
Error: [BABEL] /tmp/project/src/index.js: Cannot find module '@babel/plugin-transform-react-jsx' (While processing: "/tmp/project/node_modules/babel-preset-react-app/index.js$1")
    at Array.reduce (<anonymous>)

After eject, there’s no @babel/plugin-transform-react-jsx module inside ./node_modules, ./node_modules/babel-preset-react-app/node_modules or ./node_modules/babel-preset-react-app/node_modules/@babel/preset-react/node_modules.

I need to delete the whole node_modules and re-run yarn to make it work.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 69
  • Comments: 30 (13 by maintainers)

Commits related to this issue

Most upvoted comments

@Timer No, re-run yarn doesn’t help. I need to delete the whole node_modules and re-install all packages. I think it might be a bug in yarn package manager but I’m not sure.

See this

CRA does not include this dependency when ejecting. You’ll have to add it yourself (yarn add @babel/plugin-transform-react-jsx or npm install --save @babel/plugin-transform-react-jsx)

A proper fix in CRA will be better of course.

@lixiaoyan Yep, rm -rf node_modules && yarn worked fine for me 👌

I am facing the same issue as well.

I’ve just stumbled upon this too. My ejected setup missed two dependencies. Calling the below helped:

yarn add @babel/plugin-transform-react-jsx @babel/plugin-transform-react-jsx-self

I think this is expected. You need to re-run yarn after ejecting.

I’ve tried all the solutions posted above, but still having the issue:

Add @babel/plugin-transform-react-jsx (https://git.io/vb4yd) to the 'plugins' section of your Babel config to enable transformation.

I’ve installed

    "@babel/plugin-transform-react-jsx": "^7.10.4",
    "@babel/plugin-transform-react-jsx-self": "^7.10.4"

Tried numerous times to remove node_modules & reinstall. I’ve tried to add require.resolve('@babel/plugin-transform-react-jsx') in my webpack.config.js, and tried to add the plugin directly to the babelrc plugin section.

Does anyone have any other solution?

My current babel config in package.json:

 "babel": {
    "presets": [
      "@babel/preset-env",
      "@babel/preset-react"
    ],
    "plugins": [
      "@babel/plugin-transform-react-jsx"
    ]
  },

yarn add @babel/plugin-transform-react-jsx @babel/plugin-transform-react-jsx-self is an quicker fix for me, no need rm -rf node_modules etc

@lixiaoyan Sim, rm -rf node_modules && yarnfuncionou bem para mim👌

thanks, it worked for me too

Me and @abel1105 did some debugging work over in #6679, but I want to move the conversation here.

I don’t have a solution, but I can consistently reproduce this. Roughly here’s what’s up:

node_modules after npx create-react-app issue_6679 --typescript.

@babel/plugin-transform-react-jsx-self/
@babel/preset-react/
babel-preset-react-app/
babel-preset-react-app/node_modules/@babel/preset-react/

node_modules after yarn run eject. Here’s where we’re getting the error. If you run yarn why @babel/plugin-transform-react-jsx-self it will tell you that it’s installed because @babel/preset-react depends on it. However, that package isn’t resolvable from the nested @babel/preset-react in babel-preset-react-app/node_modules just because of how module resolution works.

- @babel/plugin-transform-react-jsx-self/
@babel/preset-react/
+ @babel/preset-react/node_modules/@babel/plugin-transform-react-jsx-self/
babel-preset-react-app/
babel-preset-react-app/node_modules/@babel/preset-react/

node_modules after rm -rf node_modules && rm yarn.lock && yarn. Everything works again.

@babel/preset-react/
@babel/preset-react/node_modules/@babel/plugin-transform-react-jsx-self/
babel-preset-react-app/
- babel-preset-react-app/node_modules/@babel/preset-react/

I’ve just stumbled upon this too. My ejected setup missed two dependencies. Calling the below helped:

yarn add @babel/plugin-transform-react-jsx @babel/plugin-transform-react-jsx-self

thanks, dude…

I’m having the same issue. @LinkChenzy suggestion worked for me.

once yarn eject has been operated, @babel/plugin-transform-react-jsx,@babel/plugin-transform-react-jsx-self and @babel/plugin-transform-react-jsx-source are deleted

See this

CRA does not include this dependency when ejecting. You’ll have to add it yourself (yarn add @babel/plugin-transform-react-jsx or npm install --save @babel/plugin-transform-react-jsx)

A proper fix in CRA will be better of course.

I Fixed this ejecting issue by adding @babel/plugin-transform-react-jsx. thx 😃

Fresh install this morning, seeing the same behaviour outlined above.