Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lixiaoyan opened this issue Dec 28, 2018 · 30 comments

Comments

@lixiaoyan
Copy link
Contributor

lixiaoyan commented Dec 28, 2018

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.

@Timer
Copy link
Contributor

Timer commented Dec 28, 2018

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

@lixiaoyan
Copy link
Contributor Author

@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.

@shreeramk
Copy link

I am facing the same issue as well.

@CiaranReen
Copy link

CiaranReen commented Jan 4, 2019

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

@mattesja
Copy link

mattesja commented Jan 5, 2019

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

@ianschmitz
Copy link
Contributor

@Timer this looks similar to the issue we're seeing that is causing our Travis builds to fail.

https://travis-ci.org/facebook/create-react-app/builds/475444651

@feugy
Copy link

feugy commented Jan 23, 2019

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.

@hwj0623
Copy link

hwj0623 commented Feb 7, 2019

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

@liiiku
Copy link

liiiku commented Mar 4, 2019

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

@Reinmar
Copy link

Reinmar commented Mar 28, 2019

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

@iansu
Copy link
Contributor

iansu commented Mar 28, 2019

We sometimes see this error in CI and sometimes we don't. I've also tried unsuccessfully to reproduce it locally with a freshly created project.

@mjraadi
Copy link

mjraadi commented Mar 29, 2019

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

@sidalidev
Copy link

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

@heyimalex
Copy link
Contributor

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/

@iansu
Copy link
Contributor

iansu commented Apr 18, 2019

Good work investigating this. So is this a bug in yarn or something in Create React App? What happens if you create an app with npm and then eject?

@heyimalex
Copy link
Contributor

Yeah, it doesn't repro when I --use-npm, so I think it's a bug in yarn. I was using 1.12.3 but just reproduced using the latest version, 1.15.2. It's weird that it's intermittent for you because I can repro every time on my machine.

@iansu
Copy link
Contributor

iansu commented Apr 18, 2019

Let's file an issue with Yarn then. Or see if one already exists.

@iansu
Copy link
Contributor

iansu commented Apr 23, 2019

@arcanis do you have any idea what might be going on here? I was going to file an issue with Yarn but I'm not even sure how to describe this problem succinctly.

@Pajn
Copy link
Contributor

Pajn commented Apr 29, 2019

I think I'm hitting the same yarn bug in a project derived from CRA but I get it with different babel packages depending on the test case.

Just as here, running npm or removing node_modules and rerunning yarn fixes the problem. It seems like yarn does not correctly verify the existing package tree somehow.

@Pajn
Copy link
Contributor

Pajn commented May 1, 2019

My current understanding is that yarn does not completely verify the package tree when running yarn for existing dependencies. Combined with the very special case of removing a dependency while at the same time installing its dependencies as first hand dependencies makes it possible for some previously transitive dependence to not get flattened and therefor be impossible to reach from packages that have been flattened (as previously discovered by @heyimalex and @abel1105).

I don't know if yarn skips this verification purposly for performance reasons or if it's a bug. But as this case should be incredibly uncommon it might be reasonable to skip it by default. However none of the yarn flags that I expected to help (--force and --check-files) does help. What I would want from yarn, I think, is a flag that verifies if all packages is placed at exactly the same nesting level as it would place them at if there were no node_modules folder.

@arcanis
Copy link
Contributor

arcanis commented May 1, 2019

@arcanis do you have any idea what might be going on here? I was going to file an issue with Yarn but I'm not even sure how to describe this problem succinctly.

No idea, sorry. It's clear it shouldn't do this, though 😕

Efficient node_modules diffing is pretty hard, and part of the reason why I don't invest too much bandwidth in node_modules at the moment. Unless someone sends a PR for the v1, this bug will likely be fixed as part of the v2 rearchitecture work, which will make PnP the default install strategy.

@iansu
Copy link
Contributor

iansu commented May 1, 2019

I'm not sure what the timeline is for v2 but I don't think this is a critical issue so we can probably wait. If someone wants to send a PR for v1 that would be great but it probably won't be me. I am curious to try this out with Yarn v2 though and see if it works.

@d4niells
Copy link

d4niells commented Aug 17, 2019

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

thanks, it worked for me too

@mrobayo
Copy link

mrobayo commented Oct 7, 2019

thanks with this line yarn add @babel/plugin-transform-react-jsx @babel/plugin-transform-react-jsx-self works for me.

@cjimmy
Copy link

cjimmy commented Oct 17, 2019

Upgrading babel core worked for me: yarn add @babel/core

@micahstubbs
Copy link

a more tightly scoped workaround, inspired by the rm -rf node_modules comments:

# delete the files on disk for the package with the problematic transitive dependency
rm -rf node_modules/babel-preset-react-app

# delete the lock file to force yarn to check all the first-level deps on disk
rm yarn.lock

# install again
yarn

This approach is somewhat faster, since we don't need to delete all of our node_modules on disk, just the node_modules/babel-preset-react-app directory 💡

@laoshaw
Copy link

laoshaw commented Oct 21, 2019

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

kwokkan added a commit to kwokkan/card-hero that referenced this issue Nov 11, 2019
kwokkan added a commit to kwokkan/card-hero that referenced this issue Nov 11, 2019
* #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: facebook/create-react-app#6099.

* #113: Add jest types for intellisense.
@alex067
Copy link

alex067 commented Jul 13, 2020

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"
    ]
  },

@mmesba
Copy link

mmesba commented Nov 26, 2020

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...

@rosedo
Copy link

rosedo commented Apr 26, 2023

For me the error was in VS Code only, so I had to add "eslint.workingDirectories": ["App", "web"] in the workspace settings. This is because the workspace had two projects in it, with two different eslint and package.json configurations.

Seems not necessary when adding"eslintConfig": {"extends": ["react-app"]} in a project using react-scripts, however using DISABLE_ESLINT_PLUGIN=true react-scripts build may be required to not break the build.

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

No branches or pull requests