我如何在 heroku 上进行 NPM install --force

Ayo*_*omi 8 npm reactjs npm-install

所以我必须使用npm i react-google-login --force将google登录组件安装到我的本地计算机中,我在Heroku上使用ci/cd连接了我的GitHub,但它拒绝在Heroku上安装react-google-login组件。请问如何npm I react-google-login --force在 Heroku 上使用?这是我在部署时遇到的错误。

-----> Installing dependencies        
remote:        Installing node modules        
remote:        npm ERR! code ERESOLVE        
remote:        npm ERR! ERESOLVE could not resolve        
remote:        npm ERR!         
remote:        npm ERR! While resolving: react-google-login@5.2.2        
remote:        npm ERR! Found: react@18.2.0        
remote:        npm ERR! node_modules/react        
remote:        npm ERR!   react@"^18.1.0" from the root project        
remote:        npm ERR!   peer react@"^16 || ^17 || ^18" from @headlessui/react@1.6.5        
remote:        npm ERR!   node_modules/@headlessui/react        
remote:        npm ERR!     @headlessui/react@"^1.6.4" from the root project        
remote:        npm ERR!   11 more (@heroicons/react, @testing-library/react, formik, ...)        
remote:        npm ERR!         
remote:        npm ERR! Could not resolve dependency:        
remote:        npm ERR! peer react@"^16 || ^17" from react-google-login@5.2.2        
remote:        npm ERR! node_modules/react-google-login        
remote:        npm ERR!   react-google-login@"^5.2.2" from the root project        
remote:        npm ERR!         
remote:        npm ERR! Conflicting peer dependency: react@17.0.2        
remote:        npm ERR! node_modules/react        
remote:        npm ERR!   peer react@"^16 || ^17" from react-google-login@5.2.2        
remote:        npm ERR!   node_modules/react-google-login        
remote:        npm ERR!     react-google-login@"^5.2.2" from the root project        
remote:        npm ERR!         
remote:        npm ERR! Fix the upstream dependency conflict, or retry        
remote:        npm ERR! this command with --force, or --legacy-peer-deps        
remote:        npm ERR! to accept an incorrect (and potentially broken) dependency resolution.        
remote:        npm ERR!         
remote:        npm ERR! See /tmp/npmcache.7FR4A/eresolve-report.txt for a full report.        
remote:                
remote:        npm ERR! A complete log of this run can be found in:        
remote:        npm ERR!     /tmp/npmcache.7FR4A/_logs/2022-07-11T20_31_06_507Z-debug-0.log        
remote: 
remote: -----> Build failed 
Run Code Online (Sandbox Code Playgroud)

Nic*_*rdy 18

将此选项放入您的存储库中.npmrc

force=true
Run Code Online (Sandbox Code Playgroud)

或者,要恢复到 npm 更宽松的对等依赖检查:

legacy-peer-deps=true
Run Code Online (Sandbox Code Playgroud)

  • 您可以将其放在项目的根目录下 (3认同)