找不到模块'@ babel / preset-plugin-transform-object-assign'

时间:2018-09-03 16:03:28

标签: reactjs webpack babel

我刚刚安装了'@ babel / preset-plugin-transform-object-assign',但似乎webpack无法识别它。尝试构建项目时出现此错误:

  

错误:找不到模块   '@ babel / preset-plugin-transform-object-assign'

这些是我的.babelrc和package.json:

.babelrc

{
  "presets": ["@babel/preset-env", "@babel/preset-react", "@babel/plugin-transform-object-assign"]
}

package.json

{
  "name": "temp",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "watch": "webpack -w --mode development --progress --color --display-error-details",
    "build": "webpack --mode production"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": "",
  "devDependencies": {
    "@babel/core": "^7.0.0",
    "@babel/plugin-transform-object-assign": "^7.0.0",
    "@babel/preset-env": "^7.0.0",
    "@babel/preset-react": "^7.0.0",
    "babel-loader": "^8.0.2",
    "react": "^16.4.2",
    "react-dom": "^16.4.2",
    "react-redux": "^5.0.7",
    "redux": "^4.0.0",
    "redux-logger": "^3.0.6",
    "redux-thunk": "^2.3.0",
    "webpack": "^4.17.1",
    "webpack-cli": "^3.1.0"
  }
}

2 个答案:

答案 0 :(得分:3)

  

在Babel中,预设是一组用于支持特定语言功能的插件

@babel/plugin-transform-object-assign是您需要在插件中添加的插件,例如:

{
  "presets": ["@babel/preset-env", 

              "@babel/preset-react"],

  "plugins": [ "@babel/plugin-transform-object-assign"]

}

Here是理解 Babel的预设和插件

的好书

答案 1 :(得分:0)

我认为您的.babelrc是错误的。

不正确。

{
  "presets": ["@babel/preset-env", "@babel/preset-react", "@babel/plugin-transform-object-assign"]
}

正确。

{
  "presets": ["env", "react"],
  "plugins": ["transform-object-assign"]
}

阅读。

https://babeljs.io/docs/en/plugins/

https://www.fullstackreact.com/articles/what-are-babel-plugins-and-presets/#how-to-use-babel-plugins-and-presets