buildpacks
buildpacks copied to clipboard
Enable Corepack before installing Node.js dependencies
Currently, deploying a Node.js app with Yarn v4 (specified in the package.json/packageManager
field) fails with the following error:
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed with status: FAILURE and message: error This project's package.json defines "packageManager": "[email protected]". However the current global version of Yarn is 1.22.20.
Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19. Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack..
References
- https://yarnpkg.com/corepack
- https://nodejs.org/api/corepack.html
@koistya , other than this, how has the switch to yarn v4 been overall? Have you deployed your v4 upgrade to prod?
Seems like yarn v4 is still very much a wip https://github.com/yarnpkg/berry/issues/3591
@devinrhode2 I've been using Yarn v2, v3, v4 with GCF for the last few years, it was working great. With some minor code tweaks required on my end, after a couple of braking changes in the GCF build infrastructure.
Yarn v4.0.1 has been released last month:
https://yarnpkg.com/blog/release/4.0
BTW, I see that Cloud Functions using Yarn v4 stopped working today with the following error message:
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed with status: FAILURE and message: error This project's package.json defines "packageManager": "[email protected]". However the current global version of Yarn is 1.22.20.
Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19. Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack..
Q: Was there an update to Cloud Functions build infrastructure recently?
I have the same problem with a Gen2 Cloud Function using Yarn v4 with corepack enable
. The workaround for me was to run yarn set version stable --yarn-path
and go back to shipping the yarn binary from the repository again.
I also had to make sure I had package.json
set properly so that detectYarnVersion()
in the buildpack for node would parse out the correct version to use in yarnURL
, and same with RequestedNodejsVersion()
for nodejs:
{
"packageManager": "[email protected]",
"engines": {
"node": "20.x.x",
"yarn": "4.0.2"
}
I'm able to deploy Gen2 functions now but it would be nice if there were an opt-in way to have the buildpack run corepack enable
. It's still an experimental feature but there is an open issue about moving it to stable that can be tracked.
Was there any progress on this? Support for Corepack is really needed.
Deploying Node.js aps to Google Cloud Functions (GCF) started to fail last week with the following error:
Error: Required package missing from disk. If you keep your packages inside your repository then restarting the Node process may be enough. Otherwise, try to run an install first.
Missing package: @google-cloud/functions-framework@npm:3.3.0
Expected package location: /www-data-home/.yarn/berry/cache/@google-cloud-functions-framework-npm-3.3.0-ac0c32fb0c-10c0.zip/node_modules/@google-cloud/functions-framework/
Even though, the yarn install
build step seems to be completed without issues:
Step #2 - "build": Running "yarn install --immutable"
Step #2 - "build": ➤ YN0000: · Yarn 4.2.2
Step #2 - "build": ➤ YN0000: ┌ Resolution step
Step #2 - "build": ➤ YN0000: └ Completed
Step #2 - "build": ➤ YN0000: ┌ Fetch step
Step #2 - "build": ➤ YN0013: │ 462 packages were added to the project (+ 184.03 MiB).
Step #2 - "build": ➤ YN0000: └ Completed in 7s 226ms
Step #2 - "build": ➤ YN0000: ┌ Link step
Step #2 - "build": ➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
Step #2 - "build": ➤ YN0007: │ protobufjs@npm:7.2.6 must be built because it never has been before or the last one failed
Step #2 - "build": ➤ YN0000: └ Completed in 0s 468ms
Step #2 - "build": ➤ YN0000: · Done with warnings in 7s 951ms
UPDATE: It seems that Yarn's global cache needs to be disabled now in order to deploy a Node.js/Yarn bundle to GCF.
yarn config set enableGlobalCache false
Deploying Node.js aps to Google Cloud Functions (GCF) started to fail last week with the following error:
Error: Required package missing from disk. If you keep your packages inside your repository then restarting the Node process may be enough. Otherwise, try to run an install first. Missing package: @google-cloud/functions-framework@npm:3.3.0 Expected package location: /www-data-home/.yarn/berry/cache/@google-cloud-functions-framework-npm-3.3.0-ac0c32fb0c-10c0.zip/node_modules/@google-cloud/functions-framework/
Even though, the
yarn install
build step seems to be completed without issues:Step #2 - "build": Running "yarn install --immutable" Step #2 - "build": ➤ YN0000: · Yarn 4.2.2 Step #2 - "build": ➤ YN0000: ┌ Resolution step Step #2 - "build": ➤ YN0000: └ Completed Step #2 - "build": ➤ YN0000: ┌ Fetch step Step #2 - "build": ➤ YN0013: │ 462 packages were added to the project (+ 184.03 MiB). Step #2 - "build": ➤ YN0000: └ Completed in 7s 226ms Step #2 - "build": ➤ YN0000: ┌ Link step Step #2 - "build": ➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental Step #2 - "build": ➤ YN0007: │ protobufjs@npm:7.2.6 must be built because it never has been before or the last one failed Step #2 - "build": ➤ YN0000: └ Completed in 0s 468ms Step #2 - "build": ➤ YN0000: · Done with warnings in 7s 951ms
UPDATE: It seems that Yarn's global cache needs to be disabled now in order to deploy a Node.js/Yarn bundle to GCF.
yarn config set enableGlobalCache false
Where did you set that yarn config set enableGlobalCache false
@koistya❓