-
-
Notifications
You must be signed in to change notification settings - Fork 27k
Babel error immediately on eject #12070
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
Comments
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.
I found that the error could be stopped by changing the {
/*... snip ... */
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
],
"env": {
"NODE_ENV": "development"
}
},
/*... snip ... */
} So maybe eject needs to do that automatically? |
@tiny-james If I do that, I just get an error from eslint, "Environment key "NODE_ENV" is unknown". I think it may just be stopping eslint from working. The underlying issue seems to be that, although
and that file does get loaded, its default export is never called when running eslint. Instead, It looks like the babel presets in package.json cause
but that will probably mess with normal Babel compilation outside of eslint. Not sure what the solution is. |
OK, here's a hack that seems to work: Update package.json to look like this:
This disables the "index" plugin when running eslint, so the "prod" one can be loaded. |
In my case, a new Error will be throwed:Parsing error: This experimental syntax requires enabling one of the following parser plugin(s): "jsx", "flow", "typescript". |
@dingziqi Hmm, not sure why it's working differently for you. I don't know if this would work, but you could try:
|
This worked for me, thank you! :) |
add |
… requires that you specify `NODE_ENV` or `BABEL_ENV` environment variables." Solution from: facebook/create-react-app#12070 (comment)
Hoping this is fixed in the eject process. Strangely but not unexpectedly, this enhanced hack does not work for me, so eslint gives me the error for every file it assesses in my project :(
|
Hi, I have met the same bug, and here are my steps to try to figure out this. npx create-react-app my-app
cd my-app
npm run eject Then, I created a {
"version": "0.2.0",
"configurations": [
{
"name": "Debug CRA ESLint",
"type": "node",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/node_modules/eslint/bin/eslint.js",
"args": [
"--debug",
"--ext",
".js",
"${workspaceFolder}/src"
],
"cwd": "${workspaceRoot}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
} And, set a breakpoint in Pressed F5 and I got this: So in my opinion, here is the reason: once you run "eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"babel": {
"presets": [
"react-app"
]
} ESLint will extend rules from // eslint-config-react-app/base.js
parserOptions: {
sourceType: 'module',
requireConfigFile: false,
babelOptions: {
presets: [require.resolve('babel-preset-react-app/prod')],
},
}, therefore, when the breakpoint is executed to one is from the in the I think that's why we got the Also, you can reproduce this "devDependencies": {
"@babel/core": "^7.18.2",
"babel-preset-react-app": "^10.0.1",
"eslint": "^8.17.0",
"eslint-config-react-app": "^7.0.1"
},
"eslintConfig": {
"extends": [
"react-app"
]
},
"babel": {
"presets": [
"react-app"
]
} As all of above, considering when we run the So I have opened a pull request #12467, and, is there a better way? : ) : ) : ) : ) : ) : ) |
"presets": [
["babel-preset-react-app", false],
"babel-preset-react-app/prod"
] |
This reverts commit f6f857f.
Add .eslintrc.js file and remove eslintConfig in package.json .
|
This adopts a solution suggested for facebook/create-react-app#12070 which may not be the best thing to do. The original problem occured in VSCode for .js files only, e.g.: Parsing error: [BABEL] /Users/cmil/Projects/dracor/einakter/tailwind.config.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/cmil/Projects/dracor/einakter/node_modules/babel-preset-react-app/index.js")
Works after ejection |
It seems like the bug is still open :-/. I can bypass this issue by setting |
The following hack worked for me: In the node_modules/babel-preset-react-app/index.js Restart the ESLint Server. (Do Ctrl+Shift+P and type "Restart ESLint Server"). |
项目报错 Using `babel-preset-react-app` requires that you specify `NODE_ENV` or `BABEL_ENV` 报错解决
can solve problems |
it's work well!thank you very much~ |
Failed to compile. [eslint] package.json: Environment key "NODE_ENV" is unknown ERROR in [eslint] package.json: Environment key "NODE_ENV" is unknown webpack compiled with 1 error Ref: facebook/create-react-app#12070 (comment)
It's now 2024, and this issue still persists. Your solution remains valid, thank you. |
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
If I start a completely fresh CRA install, and then simply eject it:
lint
script:eslint .
) throws the same error for every JS file.That error is:
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
Steps to reproduce
Set up a new app:
Add a lint command to
package.json
:Validate that it runs without error:
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:
Then, eject, and watch everything break:
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:
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.
The text was updated successfully, but these errors were encountered: