question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Babel error immediately on eject

See original GitHub issue

Describe the bug

If I start a completely fresh CRA install, and then simply eject it:

  • My text editor (VSCode) throws an error on the first line of every JS file.
  • Running eslint (by adding a lint script: eslint .) throws the same error for every JS file.

That error is:

Parsing error: [BABEL] /Users/sasha/.../App.js: Using `babel-preset-react-app` requires that you specify `NODE_ENV` or `BABEL_ENV` environment variables. Valid values are "development", "test", and "production". Instead, received: undefined. (While processing: "/Users/sasha/.../node_modules/babel-preset-react-app/index.js")

Did you try recovering your dependencies?

I did not, because I got this working on a completely fresh install (as an attempt to reproduce the problem on another repo where I’ve tried recovering my dependencies multiple times).

Which terms did you search for in User Guide?

I searched on Google and found this previous issue, as well as several SO posts that didn’t help. The solution proposed in the linked issue has already been applied to CRA, so that doesn’t seem to be the issue.

Environment

$ npx create-react-app --info
npx: installed 67 in 3.055s

Environment Info:

  current version of create-react-app: 5.0.0
  running from /Users/sasha/.npm/_npx/9320/lib/node_modules/create-react-app

  System:
    OS: macOS 12.0.1
    CPU: (10) x64 Apple M1 Pro
  Binaries:
    Node: 14.16.0 - ~/.asdf/installs/nodejs/14.16.0/bin/node
    Yarn: 1.22.10 - ~/.asdf/installs/nodejs/14.16.0/.npm/bin/yarn
    npm: 6.14.11 - ~/.asdf/installs/nodejs/14.16.0/bin/npm
  Browsers:
    Chrome: 98.0.4758.102
    Edge: Not Found
    Firefox: 96.0.2
    Safari: 15.1
  npmPackages:
    react: ^17.0.2 => 17.0.2 
    react-dom: ^17.0.2 => 17.0.2 
    react-scripts: Not Found
  npmGlobalPackages:
    create-react-app: Not Found

Steps to reproduce

Set up a new app:

npx create-react-app demo
cd demo

Add a lint command to package.json:

   "lint": "eslint ."

Validate that it runs without error:

npm run lint

Validate that the text editor (in my case VSCode) detects no issues with JS files by opening one, and seeing no error tilde at the top of the file:

image

Then, eject, and watch everything break:

npm run eject
npm run lint # throws many of the above error

Look at a file in VSCode, and it will also show the error tilde at the top of the file. On hover, it shows the aforementioned error:

image

If I return to the pre-ejected state (get rid of all eject-changes and then npm install), the issues go away.

Expected behavior

An immediately ejected app behaves identically to a non-ejected one. In particular, it doesn’t break Babel parsing and eslint.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:22
  • Comments:13

github_iconTop GitHub Comments

34reactions
tiny-jamescommented, Mar 1, 2022

I found that the error could be stopped by changing the "eslintConfig" section in the package.json to add the NODE_ENV variable:

{
/*... snip ... */
"eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ],
    "env": {
      "NODE_ENV": "development"
    }
  },
/*... snip ... */
}

So maybe eject needs to do that automatically?

12reactions
jacobwebercommented, Mar 10, 2022

@dingziqi Hmm, not sure why it’s working differently for you. I don’t know if this would work, but you could try:

    "presets": [
        ["babel-preset-react-app", false],
        'babel-preset-react-app/prod'
    ]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Solving Babel issue in Ejected React Application - Medium
It throws an Unexpected token syntax error. The issue is that Babel is no longer able to understand JSX (HTML like) syntax inside...
Read more >
Expo SDK 44 upgrade ERROR - App.js: [BABEL]: Unexpected ...
I have recently upgraded my app from SDK 40 to SDK 44 and came across this error App.js: [BABEL]: Unexpected token '.
Read more >
How To Customize ESLint Rules with an Ejected Create React ...
With a linter, an error would appear immediately and tip us off that there's a big problem. Much like how spellcheck gives a...
Read more >
The React Scripts Start Command – Create-React-App NPM ...
Although you can't see Babel or Webpack listed as dependencies in the ... The library will warn you from the console if you...
Read more >
Test runner Addon | Storybook: Frontend workshop for UI ...
The error output in the CLI is too short; The test runner seems flaky and keeps ... you can eject its configuration by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found