我的问题是,我尝试创建一个新的反应项目,在遇到很多漏洞问题后,我设法解决了其中一些问题,主要说明之一是添加这一行:
"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.
我尝试在互联网上搜索解决方案,但我发现只有一个告诉我将此插件添加到我的 devDependency 中,但这不起作用,而且我还找到了一个解决方案,告诉我输入 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:UsersOmri-PCDesktopKeeperAppnode_modules@babelplugin-proposal-private-property-in-object keeper-app-part-1-starting@1.0.0 C:UsersOmri-PCDesktopKeeperApp ├── @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" ] }
希望我给您提供了足够的信息来帮助我解决这个问题,非常感谢!
运行以下命令解决了我的问题
npm install --save-dev @babel/plugin-proposal-private-property-in-object
使用 --save-dev 将其安装在 devDependencies 下