Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Babel cannot find @babel/plugin-proposal-private-property-in-object in a React app

ErrorError: [BABEL] /app/src/index.js: Cannot find module '@babel/plugin-proposal-private-property-in-object'

Short answer

babel-preset-react-app loads this Babel plugin but your project never lists it, so it only works while something else happens to install it. Add the plugin to devDependencies. If the error shows at runtime on Heroku, devDependencies were pruned after the build, so keep Babel work in the build step.

  • Applies to Node.js 22, npm 10, react-scripts 5
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check whether the package is declared and installed in the project that throws the error.

    npm ls @babel/plugin-proposal-private-property-in-object
    grep -n "private-property-in-object" package.json
  2. 2Match what you see, then jump to its fix

    1. 1npm ls prints (empty) or the package is missing from package.json, and the error appears after a clean installThe plugin is used by the preset but not declared by your projectFix
    2. 2npm run build succeeds on the build step, but the error comes up when the dyno starts or a script runs Babel at runtime (path starting with /app)devDependencies were pruned before Babel ran on HerokuFix

What does the error look like?

  • Error: [BABEL] /app/src/index.js: Cannot find module '@babel/plugin-proposal-private-property-in-object'
  • Cannot find module '@babel/plugin-proposal-private-property-in-object'

Cause 1 of 2

The plugin is used by the preset but not declared by your project

1Check

The plugin package itself carries a warning for projects that depend on it without listing it in dependencies or devDependencies. It worked before only if another package happened to bring it.

grep -n "private-property-in-object" package.json

2Fix

Declare the plugin. Babel's own docs name @babel/plugin-transform-private-property-in-object as the maintained replacement, which you can install instead when the proposal package is not wanted.

npm install --save-dev @babel/plugin-proposal-private-property-in-object
# or the maintained plugin
npm install --save-dev @babel/plugin-transform-private-property-in-object

3Verify

A clean install and build finish without the module error.

rm -rf node_modules
npm install
npm run build

Confirmed by github.com

Did this fix it?

Cause 2 of 2

devDependencies were pruned before Babel ran on Heroku

1Check

Heroku installs devDependencies for the build, then prunes them before the slug is deployed. Anything that runs Babel later cannot find a dev-only plugin.

grep -n -A8 '"scripts"' package.json

2Fix

Do the Babel work in the build step (a build or heroku-postbuild script), which runs before pruning. If the app really needs Babel at runtime, move the plugin to dependencies or skip pruning for npm.

heroku config:set NPM_CONFIG_PRODUCTION=false

3Verify

Deploy again and read the release logs; the dyno boots without the module error.

heroku logs --tail

Confirmed by devcenter.heroku.com

Did this fix it?

How do I stop it coming back?

  • Declare every package your build config requires, even when a preset installs it for you today.
  • Commit the lockfile so every machine and CI run installs the same tree.
  • Build static React apps once and serve the build folder instead of running Babel at runtime.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.