我的問題是,我嘗試創建一個新的反應項目,在遇到很多漏洞問題後,我設法解決了其中一些問題,主要說明之一是添加這一行:
"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 下