create-react-app: [BABEL] /usr/src/app/src/index.js: Cannot find module '@babel/plugin-proposal-private-property-in-object' (0:undefined)

Describe the bug

When building a react app getting babel error. Syntax error: [BABEL] /usr/src/app/src/index.js: Cannot find module '@babel/plugin-proposal-private-property-in-object' (0:undefined)

Did you try recovering your dependencies?

Not applicable

Which terms did you search for in User Guide?

N/A

Environment

N/A

Steps to reproduce

  1. npm istall --legacy-peer-deps
  2. npm run build

Expected behavior

image

Actual behavior

image

Reproducible demo

Not applicable

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 26
  • Comments: 17

Commits related to this issue

Most upvoted comments

@vishalsinghsajwan @demitrious-tom A possible workaround given here is adding the following to the list of dependencies in the package.json file:

"@babel/plugin-proposal-private-property-in-object": "^7.21.0"

I ran into the same issue and this did the trick.

Just make sure that @babel/plugin-proposal-private-property-in-object is listed under dependencies and not devDependencies.

This is the reason you’re getting errors only when bundling for production and not development.

How do you mess up this bad is my question. Unfortunately adding “@babel/plugin-proposal-private-property-in-object”: “^7.21.0” to my dependencies and or installing doesnt work.

the solution is simple… use yarn to install the missing dependencies

yarn add @babel/plugin-proposal-private-methods — dev yarn add @babel/plugin-proposal-private-property-in-object

Possible workaround:

  • Install @babel/plugin-proposal-private-property-in-object
  • Deletenode_modules/ & package-lock.json
  • Run npm i again

same issue, adding “@babel/plugin-proposal-private-property-in-object”: “^7.21.0” in package.json file work with npm start but not npm run build

Just make sure that @babel/plugin-proposal-private-property-in-object is listed under dependencies and not devDependencies.

This is the reason you’re getting errors only when bundling for production and not development.

This worked for me and removed the warning

To make the build command work after adding “@babel/plugin-proposal-private-property-in-object”: “^7.21.0” to my package.json, I had to also add the package to the babel config as a plugin, and do the same for “@babel/plugin-proposal-private-methods”: “^7.18.6”:

// babel.config.js

plugins: [
  ...
  require('@babel/plugin-proposal-private-property-in-object').default,
  require('@babel/plugin-proposal-private-methods').default
];

I didn’t find any solution. Just one solution working for me is NODE_ENV=development, I have use this value in my .env file and on Azure server configuration i used above value and it’s working fine for me. if you use production as environment it will not work.