找不到预设的“ @ babel / env”-reactjs

时间:2018-07-04 07:52:22

标签: javascript reactjs

我想构建我的应用程序,但收到以下错误消息:

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)

我的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"
}

我的.babelrc文件:

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

我怎么了?

我的操作系统是macOS highSierra版本10.13.3节点js版本10反应了版本16.2 nodejs版本10 Webpack版本4 npm版本6.0.1

但找不到预设的“ @ babel / env”

如何解决这个问题?

1 个答案:

答案 0 :(得分:9)

这是您的.babelrc中的预设定义的问题。正确的预设名称是preset-env,而不是env

将您的.babelrc从@babel/env更新为@babel/preset-env将解决此问题。