Babel cannot find @babel/plugin-proposal-private-property-in-object in a React app
Error: [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.
Fix it fast
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.json2Match what you see, then jump to its fix
- 1
npm 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
npm 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
- 1
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.json2Fix
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-object3Verify
A clean install and build finish without the module error.
rm -rf node_modules
npm install
npm run buildConfirmed by github.com
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.json2Fix
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=false3Verify
Deploy again and read the release logs; the dyno boots without the module error.
heroku logs --tailConfirmed by devcenter.heroku.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Back end
Axios call from a React app comes back 404
404 (Not Found)
Status code 404 means a server answered, but it has nothing at that path.
3 causes, each with a fixBack end
npm start stops with Could not find a required file in a React app
Name: index.html
react-scripts checks for two files before the dev server starts: public/index.html and a src/index file.
3 causes, each with a fixBack end
Create React App says Node is too old, and npm will not run on the new one
npm does not support Node.js v10.19.0
The shell is running an old Node.js that is below the version Create React App needs.
3 causes, each with a fixBack end
npm audit stops with ENOLOCK because there is no lockfile
npm ERR! audit
npm audit sends the dependency tree from your lockfile to the registry.
2 causes, each with a fixBack end
npm says an override conflicts with a direct dependency
Override for react-error-overlay@^6.0.9 conflicts with direct dependency
npm refuses an override for a package you also depend on directly, unless both specs are exactly the same.
2 causes, each with a fixBack end
npm run build says react-scripts: Permission denied in CI
sh: react-scripts: Permission denied
The shell found node_modules/.bin/react-scripts but may not run it.
3 causes, each with a fix