When I deploy my firebase function with firebase deploy --only functions:nextServer, an error occurs as follows:
✔ functions: Finished running predeploy script.
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
✔ functions: required API cloudfunctions.googleapis.com is enabled
✔ artifactregistry: required API artifactregistry.googleapis.com is enabled
✔ functions: required API cloudbuild.googleapis.com is enabled
i functions: preparing codebase default for deployment
i functions: Loaded environment variables from .env.
i functions: preparing . directory for uploading...
i functions: packaged /Users/tony/programming/options-outcry (87.22 MB) for uploading
✔ functions: . folder uploaded successfully
i functions: updating Node.js 16 function nextServer(us-central1)...
Build failed: npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @mui/styles@5.10.3
npm ERR! Found: @types/react@18.0.17
npm ERR! node_modules/@types/react
npm ERR! dev @types/react@"18.0.17" from the root project
npm ERR! peerOptional @types/react@"^17.0.0 || ^18.0.0" from @mui/base@5.0.0-alpha.95
npm ERR! node_modules/@mui/base
npm ERR! @mui/base@"5.0.0-alpha.95" from @mui/material@5.10.3
npm ERR! node_modules/@mui/material
npm ERR! @mui/material@"^5.10.0" from the root project
npm ERR! 1 more (@mui/icons-material)
npm ERR! 10 more (@mui/icons-material, @mui/material, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional @types/react@"^17.0.0" from @mui/styles@5.10.3
npm ERR! node_modules/@mui/styles
npm ERR! @mui/styles@"^5.9.3" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @types/react@17.0.49
npm ERR! node_modules/@types/react
npm ERR! peerOptional @types/react@"^17.0.0" from @mui/styles@5.10.3
npm ERR! node_modules/@mui/styles
npm ERR! @mui/styles@"^5.9.3" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /www-data-home/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /www-data-home/.npm/_logs/2022-09-04T21_53_24_874Z-debug-0.log; Error ID: beaf8772
I searched up how to fix ERESOLVE errors in general, and most answers tell me to add the --legacy-peer-deps flag to the npm install command.
However, the install that is happening here occurs within firebase functions' deployment process, and I have not found anything that allows me to add this flag (via firebase.json or any other method).
How can I fix this build error, which only occurs when I deploy to firebase?