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

10,294

Solution 1

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

Solution 2

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

Share:
10,294
olga_babic
Author by

olga_babic

Updated on June 12, 2022

Comments

  • olga_babic
    olga_babic almost 2 years

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