Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module '@babel/preset-plugin-transform-object-assign'

I just installed '@babel/preset-plugin-transform-object-assign', but it seems like webpack doesn't recognize it. I get this error when trying to build my project:

Error: Cannot find module '@babel/preset-plugin-transform-object-assign'

These are my .babelrc and 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"
  }
}
like image 849
olga_babic Avatar asked Sep 03 '18 16:09

olga_babic


2 Answers

In Babel, a preset is a set of plugins used to support particular language features

and @babel/plugin-transform-object-assign is plugin that you need to add in plugins like:

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

              "@babel/preset-react"],

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

}

Here is a good read to understand Babel's presets and plugins

like image 61
Sakhi Mansoor Avatar answered Nov 18 '22 07:11

Sakhi Mansoor


I think that your .babelrc is wrong.

incorrect.

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

correct.

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

Read this.

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

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

like image 1
seunggabi Avatar answered Nov 18 '22 07:11

seunggabi