firebase-tools: Firebase Function deployment fails with error "Build failed: npm ERR! code ERESOLVE"

[REQUIRED] Environment info

“firebase”: “^9.9.0”, “firebase-admin”: “^10.0.2”, “firebase-functions”: “^3.16.0”,

Platform: Windows

Step #1: λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
Step #1: ○  (Static)  automatically rendered as static HTML (uses no initial props)
Step #1: 
Step #1: ✔  functions: Finished running predeploy script.
Step #1: i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
Step #1: i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
Step #1: i  functions: ensuring required API artifactregistry.googleapis.com is enabled...
Step #1: ✔  functions: required API cloudfunctions.googleapis.com is enabled
Step #1: ✔  functions: required API cloudbuild.googleapis.com is enabled
Step #1: ✔  functions: required API artifactregistry.googleapis.com is enabled
Step #1: i  functions: preparing . directory for uploading...
Step #1: i  functions: packaged . (14.46 MB) for uploading
Step #1: ✔  functions: . folder uploaded successfully
Step #1: i  functions: updating Node.js 16 function nextServer(us-central1)...
.
Step #1: 
Step #1: Functions deploy had errors with the following functions:
Step #1: 	nextServer(us-central1)
Step #1: i  functions: cleaning up build files...
Step #1: ⚠  functions: Unhandled error cleaning up build images. This could result in a small monthly bill if not corrected. You can attempt to delete these images by redeploying or you can delete them manually at https://console.cloud.google.com/artifacts/docker/my-project/us-central1/gcf-artifacts
Step #1: 
Step #1: Error: There was an error deploying functions
Finished Step #1
ERROR
ERROR: build step 1 "gcr.io/my-project/firebase" failed: step exited with non-zero status: 2

I get this above error every time I try to deploy my next js project using cloud build. I checked the function logs on cloud functions console as well as on the firebase console and here what it is showing -

Deployment failure:
Build failed: npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @mui/styles@5.9.3
npm ERR! Found: @types/react@18.0.15
npm ERR! node_modules/@types/react
npm ERR! dev @types/react@"18.0.15" from the root project
npm ERR! peerOptional @types/react@"^17.0.0 || ^18.0.0" from @mui/base@5.0.0-alpha.92
npm ERR! node_modules/@mui/base
npm ERR! @mui/base@"5.0.0-alpha.92" from @mui/lab@5.0.0-alpha.93
npm ERR! node_modules/@mui/lab
npm ERR! @mui/lab@"^5.0.0-alpha.93" from the root project
npm ERR! @mui/base@"5.0.0-alpha.92" from @mui/material@5.9.3
npm ERR! node_modules/@mui/material
npm ERR! @mui/material@"^5.9.3" from the root project
npm ERR! 2 more (@mui/icons-material, @mui/lab)
npm ERR! 9 more (@mui/icons-material, @mui/lab, @mui/material, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional @types/react@"^17.0.0" from @mui/styles@5.9.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.48
npm ERR! node_modules/@types/react
npm ERR! peerOptional @types/react@"^17.0.0" from @mui/styles@5.9.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-08-03T12_42_24_502Z-debug-0.log; Error ID: beaf8772

At first, I thought it is giving the deployment error because of the material UI library dependency issue. I’ve updated the libraries to their latest version, but still, the deployment fails.

[REQUIRED] Steps to reproduce

I’m just deploying my next js application using cloud build.

[REQUIRED] Expected behavior

Deployment should happen successfully with no errors

[REQUIRED] Actual behavior

Deployment fails

This is what my package.json contains -

"firebase": "^9.9.0",
"firebase-admin": "^10.0.2",
"firebase-functions": "^3.16.0",
"@mui/icons-material": "^5.8.4",
"@mui/lab": "^5.0.0-alpha.93",
"@mui/material": "^5.9.3",
"@mui/styles": "^5.9.3",
"next": "12.2.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-firebaseui": "^6.0.0"

I’ve searched a lot about this artifacts files and also manually deleted them from the cloud console. I’m not able to understand what causing this deployment issue?

Can someone help me with that? How we can fix it?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (4 by maintainers)

Most upvoted comments

I’m faced with a similar error.

I’m referencing a library in the same repo in my package.json as follows:

"dependencies": {
    "@MYLIBRARY/shared": "file:../../shared",

Trying to deploy firebase functions yields

...
Build failed: npm ERR! code EUSAGE
...
npm ERR! Invalid: lock file's @MYLIBRARY/shared@1.0.0 does not satisfy @MYLIBRARY/shared@
...

Adding legacy-peer-deps to my .npmrc before npm install didn’t seem to help.

I found a workaround (though not a proper fix):

Doesn’t work:

npm install
firebase deploy

Works:

npm install
rm package-lock.json
firebase deploy

Removing package-lock.json works for me!

Thanks for the clue @LaithAzzam - it looks like recent version of npm (packaged with node) included a “bugfix” that’s now stricter on invalid dependency graph present in your package-lock.json. So npm ci could suddenly start failing w/ the latest version of node 16.

https://github.com/npm/cli/issues/5113

Unfortunately, there isn’t a way that I know to pin the version of nodejs16 used on Google Cloud Functions platform (in a way, that is one of the benefit of using GCF - that any security patches/minor updates are automatically applied to your application).

I’m glad to see @krishna-fenixwork originally reported issue be fixed.

Note to others - Sudden appearance of Build failed: npm ERR! code ERESOLVE on your function deployment means your package-lock.json file had latent “bug” i.e. incompatible dependency graph that is now being surfaced. GCF platform recently upgraded to using node 16.16.0 which bundles npm binary that errors out when given invalid dep graph. Please try installing this version of node and run npm ci to reproduce the error locally.

npm core team isn’t pursuing a plan to revert this change and recommend users to fix the conflicting dependencies. You can also try using the --legacy-peer-deps flag on npm install command to override the conflicting deps.

@taeold 🙏 Anytime! Ty for the response and explanation!

For anyone else that may stumble on this, a lot of our dependency issues were stemming from our upgrade to React 17.

Downgrading to React 16.13.0 cleaned up most of the errors, eventually getting us to successful builds with the fewest additional upgrade / downgrades.

This change is probably better for the long run, given we kept de-prioritizing managing our packages 🙃😅

facing the same issue UPDATE: Just started working for me now.

With no changes? Facing the same issue 🤔

Yeah, I didn’t change anything. I guess it was an issue with Cloud Build. I tried deploying one single function and it got deployed successfully.