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"
}
}
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With