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
npx create-react-app project
cd project
yarn eject
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
- add react-jsx-self plugin explicitly see https://github.com/facebook/create-react-app/issues/6099 for details — committed to just-boris/create-preact-app by just-boris 5 years ago
- #113: Add a test to test the test script. Also fix a create react app bug: https://github.com/facebook/create-react-app/issues/6099. — committed to kwokkan/card-hero by kwokkan 5 years ago
- Feature/113 react eject (#160) * #113: Eject react app so tests can be ran. * #113: Add a test to test the test script. Also fix a create react app bug: https://github.com/facebook/create-react... — committed to kwokkan/card-hero by kwokkan 5 years ago
@Timer No, re-run
yarn
doesn’t help. I need to delete the wholenode_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
ornpm 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:
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
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:
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 etcthanks, it worked for me too
For me that workaround at SO helped. https://stackoverflow.com/questions/53327625/cannot-find-module-babel-plugin-transform-react-jsx-source-when-running-react
Nevertheless a real fix would be nice 😃
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
.node_modules after
yarn run eject
. Here’s where we’re getting the error. If you runyarn 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
inbabel-preset-react-app/node_modules
just because of how module resolution works.node_modules after
rm -rf node_modules && rm yarn.lock && yarn
. Everything works again.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 deletedI Fixed this ejecting issue by adding @babel/plugin-transform-react-jsx. thx 😃
Fresh install this morning, seeing the same behaviour outlined above.