Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Couldn't find preset "@babel/env" - reactjs

I want to build my application but I got this error message:

ERROR in ./src/index.js
Module build failed: Error: Couldn't find preset "@babel/env" relative to directory "/Users/mohammadmehdi/Documents/Work/sevenapp"
    at /Users/mohammadmehdi/Documents/Work/sevenapp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
    at Array.map (<anonymous>)
    at OptionManager.resolvePresets (/Users/mohammadmehdi/Documents/Work/sevenapp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
    at OptionManager.mergePresets (/Users/mohammadmehdi/Documents/Work/sevenapp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
    at OptionManager.mergeOptions (/Users/mohammadmehdi/Documents/Work/sevenapp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
    at OptionManager.init (/Users/mohammadmehdi/Documents/Work/sevenapp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
    at File.initOptions (/Users/mohammadmehdi/Documents/Work/sevenapp/node_modules/babel-core/lib/transformation/file/index.js:212:65)
    at new File (/Users/mohammadmehdi/Documents/Work/sevenapp/node_modules/babel-core/lib/transformation/file/index.js:135:24)
    at Pipeline.transform (/Users/mohammadmehdi/Documents/Work/sevenapp/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
    at transpile (/Users/mohammadmehdi/Documents/Work/sevenapp/node_modules/babel-loader/lib/index.js:50:20)
    at Object.module.exports (/Users/mohammadmehdi/Documents/Work/sevenapp/node_modules/babel-loader/lib/index.js:173:20)

my package.json:

{
  "name": "sevenapp",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.18.0",
    "babel-preset-react": "^6.24.1",
    "bootstrap": "^4.0.0",
    "html-webpack-plugin": "^3.2.0",
    "jquery": "^3.3.1",
    "rc-pagination": "^1.16.4",
    "react": "^16.2.0",
    "react-countup": "^3.0.3",
    "react-dom": "^16.2.0",
    "react-paginate": "^5.2.3",
    "react-player": "^1.6.4",
    "react-popup": "^0.9.3",
    "react-redux": "^5.0.7",
    "react-router": "^4.2.0",
    "react-router-dom": "^4.2.2",
    "react-scripts": "1.1.1",
    "redux": "^4.0.0"
  },
  "scripts": {
    "start": "webpack-dev-server --mode development --open",
    "build": "webpack --mode production",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "description": ":D",
  "main": "index.js",
  "devDependencies": {
    "@babel/preset-env": "^7.0.0-beta.51",
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.4",
    "babel-preset-env": "^1.7.0",
    "babel-preset-stage-3": "^6.24.1",
    "css-loader": "^0.28.11",
    "jshint": "^2.9.5",
    "jshint-loader": "^0.8.4",
    "style-loader": "^0.21.0",
    "url-loader": "^1.0.1",
    "webpack": "^4.6.0",
    "webpack-cli": "^2.0.15"
  },
  "author": "MM",
  "license": "ISC"
}

my .babelrc file:

{
    "presets": [
        "@babel/env",
        "@babel/preset-react",
        [
            "@babel/preset-stage-3",
            {
                "decoratorsLegacy": true
            }
        ]
    ]
}

what is my wrong?

my OS is macOS highSierra version 10.13.3 node js version 10 react version 16.2 nodejs version 10 webpack version 4 npm version 6.0.1

but couldn't find preset "@babel/env"

How to solve this problem???

like image 921
Mahdi Avatar asked Jul 04 '18 07:07

Mahdi


1 Answers

This is the problem with your presets definition in your .babelrc. The correct preset name is preset-env, not env.

Update your .babelrc from @babel/env to @babel/preset-env will solve the problem.

like image 191
Thai Duong Tran Avatar answered Oct 14 '22 23:10

Thai Duong Tran