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 3 years ago
  • Reactions: 26
  • Comments: 20

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.

Possible workaround:

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

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

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

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

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.

Adding "@babel/plugin-proposal-private-property-in-object": "^7.21.0" in package.json file is not working for me. I also see on Azure server when i creating build with NODE_ENV=production then i am getting this issue but if i build with development then it’s working fine without any error.

[eslint] 
src/index.js
Syntax error: [BABEL] /tmp/8db835b2a16ede0/src/index.js: Cannot find module '@babel/plugin-proposal-private-property-in-object' (0:undefined)
Require stack:
- /tmp/8db835b2a16ede0/node_modules/babel-preset-react-app/create.js
- /tmp/8db835b2a16ede0/node_modules/babel-preset-react-app/index.js
- /tmp/8db835b2a16ede0/node_modules/@babel/core/lib/config/files/module-types.js
- /tmp/8db835b2a16ede0/node_modules/@babel/core/lib/config/files/configuration.js
- /tmp/8db835b2a16ede0/node_modules/@babel/core/lib/config/files/index.js
- /tmp/8db835b2a16ede0/node_modules/@babel/core/lib/index.js
- /tmp/8db835b2a16ede0/node_modules/@rollup/plugin-babel/dist/index.js
- /tmp/8db835b2a16ede0/node_modules/workbox-build/build/lib/bundle.js
- /tmp/8db835b2a16ede0/node_modules/workbox-webpack-plugin/build/generate-sw.js
- /tmp/8db835b2a16ede0/node_modules/workbox-webpack-plugin/build/index.js
- /tmp/8db835b2a16ede0/node_modules/react-scripts/config/webpack.config.js
- /tmp/8db835b2a16ede0/node_modules/react-scripts/scripts/build.js (While processing: "/tmp/8db835b2a16ede0/node_modules/babel-preset-react-app/prod.js")

After selecting these versions (normal dependencies, not dev), normal production build worked for me:

    "@babel/core": "^7.22.5",
    "@babel/plugin-proposal-private-property-in-object": "^7.21.11",

PS: It is still throwing this warning:

One of your dependencies, babel-preset-react-app, is importing the
"@babel/plugin-proposal-private-property-in-object" package without
declaring it in its dependencies. This is currently working because
"@babel/plugin-proposal-private-property-in-object" is already in your
node_modules folder for unrelated reasons, but it may break at any time.
babel-preset-react-app is part of the create-react-app project, which
is not maintianed anymore. It is thus unlikely that this bug will
ever be fixed. Add "@babel/plugin-proposal-private-property-in-object" to
your devDependencies to work around this error. This will make this message
go away.

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
];

“@babel/plugin-transform-private-property-in-object”: “^7.24.6” is the current version

In my current project, if I use @babel/plugin-transform-private-property-in-object instead of @babel/plugin-proposal-private-property-in-object, I still receive the following error on build:

Error: Cannot find package '@babel/plugin-proposal-private-property-in-object' imported from /Users/redacted/Development/BlueBubbles/bluebubbles-server/packages/server/babel-virtual-resolve-base.js
[1]     at new NodeError (/Users/redacted/Development/BlueBubbles/bluebubbles-server/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:195:5)
[1]     at packageResolve (/Users/redacted/Development/BlueBubbles/bluebubbles-server/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:899:9)
[1]     at moduleResolve (/Users/redacted/Development/BlueBubbles/bluebubbles-server/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:939:18)

The only fix is to install @babel/plugin-proposal-private-property-in-object, even if my webpack configuration uses the “official” (non-proposal) package. I’m not entirely sure what is using the proposal package rather than the official.

EDIT: Looks like it’s being used by babel-preset-react-app, which is a sub-dependency of react-scripts, which hasn’t been updated since 2022. I guess we’ll need to keep it installed for now