Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Did vendored Dependencies changes for NodeJS Application?

Hello,

I want Cloud Build to leverage the node_modules folder that is part of my zip. For this, I followed the instructions provided here, adding GOOGLE_VENDOR_NPM_DEPENDENCIES=true as a build variable to my function.

Screenshot 2024-04-17 at 15.51.03.pngScreenshot 2024-04-17 at 15.48.42.png

From the attached build logs, I can safely say it's been passed on to build pack (with the correct value) but ultimately then ignored.  Within the build phase, I can see it is still performing a yarn install will yarn install --non-interactive --prefer-offline, this is something I would not expected to happen.

Hence, I wanted to know if there has been a change to how vendored Dependencies for NodeJS work or if I'm overlooking something.

 

 

Solved Solved
0 5 571
1 ACCEPTED SOLUTION

Looking again at the documentation you referenced, it says

    npm install

It doesn't have an option for yarn install (my experience is that the docs usually call out both npm and yarn install). Given that it didn't mention yarn install, maybe it means it will only work with npm as the package manager....?🤔

 

......NoCommandLine ......
https://nocommandline.com
        Analytics & GUI for 
App Engine & Datastore Emulator

 

View solution in original post

5 REPLIES 5

1. Did you remember to remove node_modules from the .gcloudignore file in your working directory?

2. Did you also remember to check your local Node.js version is the same as the one you specify during deployment

 

......NoCommandLine ......
https://nocommandline.com
        Analytics & GUI for 
App Engine & Datastore Emulator

Actually, initially, there was no cloudignore present. Then, I added one that excluded only the README.md, but that did not change anything. The Node version is the same, and the weirdest thing is that when I replaced yarn with npm as package manager (not changing anything else), it started working.

Looking again at the documentation you referenced, it says

    npm install

It doesn't have an option for yarn install (my experience is that the docs usually call out both npm and yarn install). Given that it didn't mention yarn install, maybe it means it will only work with npm as the package manager....?🤔

 

......NoCommandLine ......
https://nocommandline.com
        Analytics & GUI for 
App Engine & Datastore Emulator

 

Well, I was under the impression that, given this section, they would support that feature equally for all the supported package managers. But you seem to have a valid point.

This feels broken IMO. I currently package my node_modules ahead of time with pnpm that become part my cloud function zip file. Why should it matter what package manager we use to install our node_modules? Currently I am unable to get my cloud function to run because build pack runs npm install despite this environment variable being set. 

I get error:

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed with status: FAILURE and message: npm error code EUNSUPPORTEDPROTOCOL
npm error Unsupported URL Type "workspace:": workspace:*

I use pnpm to install dependencies including workspace dependencies (monorepo) before I upload my zip file because build pack is not equipped to properly handle those types of dependencies.