babel-preset-react-app正在导入“@babel/plugin-proposal-private-property-in-object”包,但未在其依赖项中声明

x6h2sr28  于 2023-06-20  发布在  Babel
关注(0)|答案(7)|浏览(1019)

我的问题是,我试图创建一个新的react项目,在遇到很多漏洞问题后,我设法解决了其中一些问题,其中一个主要指令是添加这一行:

"overrides": {
    "@svgr/webpack": "$@svgr/webpack"
  },

我的package.json文件。一旦我这样做了,我必须删除我的node_modules文件夹并重新使用npm install,现在我在输入npm start后得到一个babel错误。

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.

我试图在互联网上搜索解决方案,我发现只有一个告诉我将此插件添加到我的devDependencies中,但没有工作,我还发现了一个解决方案,告诉键入CI= npm run build也没有工作。
这就是我在输入npm list @babel/plugin-proposal-private-property-in-object时遇到的情况:

npm ERR! code ELSPROBLEMS
npm ERR! invalid: @babel/plugin-proposal-private-property-in-object@7.21.0-placeholder-for-preset-env.2 C:\Users\Omri-PC\Desktop\KeeperApp\node_modules\@babel\plugin-proposal-private-property-in-object
keeper-app-part-1-starting@1.0.0 C:\Users\Omri-PC\Desktop\KeeperApp
├── @babel/plugin-proposal-private-property-in-object@7.21.0-placeholder-for-preset-env.2 invalid: "^x.x.x" from the root project
└─┬ @svgr/webpack@8.0.1 overridden
  └─┬ @babel/preset-env@7.22.5
    └── @babel/plugin-proposal-private-property-in-object@7.21.0-placeholder-for-preset-env.2 deduped invalid: "^x.x.x" from the root project

这就是我的package.json文件的样子,如果它以某种方式帮助计算:

{
  "name": "keeper-app-part-1-starting",
  "version": "1.0.0",
  "description": "",
  "keywords": [],
  "main": "src/index.js",
  "dependencies": {
    "react": "18.2.0",
    "react-dom": "18.2.0"
  },
  "devDependencies": {
    "@svgr/webpack": "^8.0.1",
    "react-scripts": "5.0.1",
    "typescript": "5.1.3"
  },
  "overrides": {
    "@svgr/webpack": "$@svgr/webpack"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

希望我给了你足够的信息,以便帮助我解决这个问题,非常感谢!

ukxgm1gy

ukxgm1gy1#

感谢所有人,最终这解决了我的问题:npm install --save-dev @babel/plugin-proposal-private-property-in-object --legacy-peer-deps

ghg1uchk

ghg1uchk2#

下面是对我有用的babel包的组合:

"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",
}

重要步骤:@babel/plugin-proposal-private-property-in-object添加到.babelrc插件。就像这样:

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

参见GitHub Issue:https://github.com/babel/babel-plugin-proposal-private-property-in-object/issues/1

dpiehjr4

dpiehjr43#

运行下面的命令解决了我的问题
npm install --save-dev @babel/plugin-proposal-private-property-in-object
使用--save-dev在devDependencies下安装它

wb1gzix0

wb1gzix04#

我尝试将"@babel/plugin-proposal-private-property-in-object": "^7.21.11"添加到devDependencies,我的CI=npm run build成功完成。

frebpwbc

frebpwbc5#

今天也开始有这个问题。已将推荐的软件包添加到devDependencies,但仍然没有成功。

**更新:**更新我的全局yarn安装(或者你选择的包管理器)似乎可以解决这个问题。
**后续:**此修复适用于我的开发和主机服务器,但不适用于我的生产节点容器。

llew8vvj

llew8vvj6#

今天早些时候,我正在做一个业余爱好项目,得到了同样的警告。您只需要在项目中安装版本的devDependencies对象下添加"@babel/plugin-proposal-private-property-in-object"的条目即可。您可以在以下路径中找到项目的已安装版本:

node_modules/@babel/plugin-proposal-private-property-in-object/package.json

有了这个版本后,只需在项目的主package.json文件(包含runtest等命令的文件)中更新上面提到的条目即可。
下面是我修改的package.json文件的内容,以消除警告消息:

{
  "name": "clothes_shop",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4"
  },
  "devDependencies": {
    "@babel/plugin-proposal-private-property-in-object": "^7.21.0-placeholder-for-preset-env.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}
t98cgbkg

t98cgbkg7#

我今天也遇到了这个问题。我通过从here中添加所需的lib来解决这个问题,之后“npm start”和“npm run build”对我来说很好。注:使用的版本号**^7.21.11**

相关问题