admin管理员组

文章数量:1193346

I created a React App using npx create-react-app my_app but when I am running the app using npm start, I am getting the following error,

I tried installing the package '@babel/plugin-proposal-private-property-in-object' using npm install @babel/plugin-proposal-private-property-in-object but still getting the same error. How to solve this?

I created a React App using npx create-react-app my_app but when I am running the app using npm start, I am getting the following error,

I tried installing the package '@babel/plugin-proposal-private-property-in-object' using npm install @babel/plugin-proposal-private-property-in-object but still getting the same error. How to solve this?

Share Improve this question asked May 26, 2023 at 16:43 SantamSantam 3011 gold badge3 silver badges12 bronze badges 3
  • 1 Says here that this plugin is already included in babel/preset-env. Are you sure you need to be installing it separately at all? Might be a bug with create-react-app if you're actually doing a fresh bootstrap – Mike K Commented May 26, 2023 at 16:47
  • No we do not need to install the package separately, Idk why it's showing an error this time. – Santam Commented May 26, 2023 at 17:19
  • 3 Please don't post code, exceptions, or results as images. They can't be copied (partly) for answering and their "text" won't appear in search engines. – Gert Arnold Commented May 27, 2023 at 18:34
Add a comment  | 

6 Answers 6

Reset to default 6

Here is a combination of babel packages that worked for me:

"devDependencies": {
    "@babel/core": "7.22.5",
    "@babel/eslint-parser": "7.22.5",
    "@babel/plugin-proposal-private-property-in-object": "7.21.11",
    "@babel/preset-env": "7.22.5",
}

IMPORTANT STEP

Add @babel/plugin-proposal-private-property-in-object to .babelrc plugins as well.

Something like this:

"plugins": [
    ["@babel/plugin-proposal-private-property-in-object", { "loose": true }]
]

This error occurs when Babel plugin is missing or not installed. Add "@babel/plugin-proposal-private-property-in-object": "^7.21.0", to the list of dependencies in the package.json file like:

"dependencies": {

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

for me the only thing helps was to install the @babel/plugin-proposal-private-property-in-object package and then remove the node_modules folder with rm -rf node_modules --force and then reinstall it

After receiving a warning "One of your dependencies, babel-preset-react-app, is importing the package "@babel/plugin-proposal-private-property-in-object" without declaring it in its dependencies. This is currently working because the package "@babel/plugin-proposal-private-property-in-object" is already in your node_modules folder for unrelated reasons, but it may break at any time." I reinstalled @babel/plugin-proposal-private-property-in-object from the website https://www.npmjs.com/package/@babel/plugin-proposal-private-property-in-object.

I discovered that when you save this code in package.json, an additional error will show up. However, if you remove it and save it again, both issues are resolved and the code compiles perfectly.

  "devDependencies": {
    "@babel/plugin-transform-private-property-in-object": "^7.23.3"
  }

(If someone knows a permanent solution, please do reply to this)

Step 1: Add a babel.config.js file to the root of the project

Step2: 2: Run this code in the terminal

npm i @babel/plugin-transform-private-property-in-object

Step 3: Add the code below to the Babel.config file

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

Step 4: Add these lines of code to the package.json file

  "devDependencies": {
  "@babel/plugin-transform-private-property-in-object": "^7.23.3"
 },

本文标签: