2

I am trying to deploy a NodeJS Google Cloud Function using the gcloud CLI. We use a couple private NPM modules in our devDependencies, but we don't need them in our production environment. When I try to deploy the function, I get a 401 error because the cloud build instance is not authorized to pull the modules (expected).

What I don't understand is why it is running yarn install --non-interactive --frozen-lockfile. The documentation clearly states that is should be installing dependencies using the --production flag (source - https://cloud.google.com/functions/docs/writing/specifying-dependencies-nodejs#installing_dependencies_during_deployment):

In the Node.js 8 runtime and higher, if a yarn.lock file exists, Cloud Functions instead uses the yarn install command:

yarn install --production

I can see that the /workspace/yarn.lock does in fact exist in the workspace, and it correctly detects that it should use yarn, so I can't see why it would be behaving this way.

Am I missing something here?

Edit: I am not using a custom build step. package.json below:

{
  "name": "imaware-fhir-events-backend",
  "version": "0.0.0",
  "license": "UNLICENSED",
  "main": "main.js",
  "scripts": {
    "nx": "nx",
    "start": "nx serve",
    "build": "nx build",
    "test": "nx test",
    "lint": "nx workspace-lint && nx lint",
    "e2e": "nx e2e",
    "affected:apps": "nx affected:apps",
    "affected:libs": "nx affected:libs",
    "affected:build": "nx affected:build",
    "affected:e2e": "nx affected:e2e",
    "affected:test": "nx affected:test",
    "affected:lint": "nx affected:lint",
    "affected:dep-graph": "nx affected:dep-graph",
    "affected": "nx affected",
    "format": "nx format:write",
    "format:write": "nx format:write",
    "format:check": "nx format:check",
    "update": "nx migrate latest",
    "workspace-generator": "nx workspace-generator",
    "dep-graph": "nx dep-graph",
    "help": "nx help"
  },
  "private": true,
  "dependencies": {
    "@ahryman40k/ts-fhir-types": "^4.0.34",
    "@google-cloud/functions-framework": "^1.7.1",
    "@google-cloud/logging-bunyan": "^3.0.2",
    "@google-cloud/pubsub": "^2.9.0",
    "bunyan": "^1.8.15",
    "dayjs": "^1.10.4",
    "fp-ts": "^2.9.5",
    "googleapis": "^67.1.0",
    "simple-hl7": "^3.2.1"
  },
  "devDependencies": {
    "@imaware/fhir-gen": "^0.2.1",
    "@nrwl/cli": "11.2.12",
    "@nrwl/eslint-plugin-nx": "11.2.12",
    "@nrwl/jest": "11.2.12",
    "@nrwl/linter": "11.2.12",
    "@nrwl/node": "11.2.12",
    "@nrwl/tao": "11.2.12",
    "@nrwl/workspace": "11.2.12",
    "@types/jest": "26.0.8",
    "@types/node": "12.12.38",
    "@typescript-eslint/eslint-plugin": "4.3.0",
    "@typescript-eslint/parser": "4.3.0",
    "dotenv": "6.2.0",
    "eslint": "7.10.0",
    "eslint-config-prettier": "6.0.0",
    "jest": "26.2.2",
    "nx": "^11.3.0",
    "prettier": "2.2.1",
    "ts-jest": "26.4.0",
    "ts-node": "~9.1.1",
    "tsc": "^1.20150623.0",
    "typescript": "~4.0.3"
  }
}
  • Edit your question and add your package.json file. Are you running a custom build step as advised [here](https://cloud.google.com/functions/docs/writing/specifying-dependencies-nodejs#executing_custom_build_steps_during_deployment) or specify any scripts at all that could be messing up the deployment? – Daniel Ocando Feb 19 '21 at 08:45
  • @DanielOcando Thanks for the response, I've edited it. I didn't see any scripts which looked like they would cause problems. – Chris Manzi Feb 19 '21 at 13:39

1 Answers1

0

I have checked this and the yarn install command also sets the NODE_ENV variable to “production”, which is what the “--production” flag does.

The other two flags that are added do not impact the command as “--non-interactive” & “--frozen-lockfile” have behaviours that are expected from a deployment using Cloud Build.

enter image description here

mgoya
  • 512
  • 3
  • 12