-1

I want to automatically build my nextjs app using Google's Cloud Build. However, the trigger throws an error after pushing to my repository.

Error Message:

Starting Step #0
Step #0: Already have image (with digest): gcr.io/cloud-builders/npm
Step #0: 
Step #0: > next-kara@0.1.0 prepare /workspace
Step #0: > npm run gcp-build
Step #0: 
Step #0: 
Step #0: > next-kara@0.1.0 gcp-build /workspace
Step #0: > next build
Step #0: 
Step #0: sh: 1: next: not found
Step #0: npm ERR! code ELIFECYCLE
Step #0: npm ERR! syscall spawn
Step #0: npm ERR! file sh
Step #0: npm ERR! errno ENOENT
Step #0: npm ERR! next-kara@0.1.0 gcp-build: `next build`
Step #0: npm ERR! spawn ENOENT
Step #0: npm ERR! 
Step #0: npm ERR! Failed at the next-kara@0.1.0 gcp-build script.
Step #0: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Step #0: npm WARN Local package.json exists, but node_modules missing, did you mean to install?
Step #0: 
Step #0: npm ERR! A complete log of this run can be found in:
Step #0: npm ERR!     /builder/home/.npm/_logs/2021-04-18T13_48_44_437Z-debug.log
Step #0: npm ERR! code ELIFECYCLE
Step #0: npm ERR! errno 1
Step #0: npm ERR! next-kara@0.1.0 prepare: `npm run gcp-build`
Step #0: npm ERR! Exit status 1
Step #0: npm ERR! 
Step #0: npm ERR! Failed at the next-kara@0.1.0 prepare script.
Step #0: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Step #0: npm WARN Local package.json exists, but node_modules missing, did you mean to install?
Step #0: 
Step #0: npm ERR! A complete log of this run can be found in:
Step #0: npm ERR!     /builder/home/.npm/_logs/2021-04-18T13_48_44_465Z-debug.log
Finished Step #0
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/npm" failed: step exited with non-zero status: 1

My cloudbuild.yaml file looks like:

steps:
- name: "gcr.io/cloud-builders/npm"
  args: ["install", "run", "prepare"] # "install added after comment"
- name: "gcr.io/cloud-builders/gcloud"
  args: ["app", "deploy", "app.yaml"]
timeout: "1600s"

And my package.json:

{
  "name": "next-kara",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "gcp-build": "next build",
    "prepare": "npm run gcp-build",
    "start": "next start -p $PORT",
    "preinstall": "node lock_node_version.js"
  }

Any idea? The App works fine on Google's App Engine when scripts are executed locally.

Thanks

Update

As in the comments suggested I also tried to execute the trigger when changing to node version 14.0.0 and 14.10.0 (latest build). Same behavior; executed locally the app works on Google's App Engine but same error when executed with Github trigger.

Error after adding "install" to cloudbuild.yaml file:

Step #0: make: Leaving directory '/workspace/node_modules/contextify/build'
Step #0: gyp ERR! build error 
Step #0: gyp ERR! stack Error: `make` failed with exit code: 2
Step #0: gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
Step #0: gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
Step #0: gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
Step #0: gyp ERR! System Linux 5.4.0-1040-gcp
Step #0: gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
Step #0: gyp ERR! cwd /workspace/node_modules/contextify
Step #0: gyp ERR! node -v v14.10.0
Step #0: gyp ERR! node-gyp -v v5.1.0
Step #0: gyp ERR! not ok 
Step #0: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/watchpack-chokidar2/node_modules/fsevents):
Step #0: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
Step #0: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/fsevents):
Step #0: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
Step #0: 
Step #0: npm ERR! code ELIFECYCLE
Step #0: npm ERR! errno 1
Step #0: npm ERR! contextify@0.1.15 install: `node-gyp rebuild`
Step #0: npm ERR! Exit status 1
Step #0: npm ERR! 
Step #0: npm ERR! Failed at the contextify@0.1.15 install script.
Step #0: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Maeaex1
  • 703
  • 7
  • 36
  • a step for "npm install" is missing. – Parth Ghiya Apr 18 '21 at 15:26
  • I'll try but receive another error (updated my question). But why is npm install necessary when I run script `gcloud app deploy app.yaml` locally does not require an additional npm install? – Maeaex1 Apr 18 '21 at 15:57
  • npm install is needed because node_modules are not part of repository or in this case image. The process is 1. extract source 2. install dependencies 3. Run Code As for your other issues is mostly related due to some mismatched dependencies. `node-gyp rebuild` delete node_modules and retry – Parth Ghiya Apr 18 '21 at 16:46
  • Are you developing on Mac? Your dependency seams only compliant with Mac – guillaume blaquiere Apr 18 '21 at 19:06
  • @guillaumeblaquiere, I am developing on Windows, but my colleagues on Mac. Seems like App Engine VM is running on Linux. However, I have no Problem running the app locally on my windows machine. – Maeaex1 Apr 19 '21 at 08:46

1 Answers1

2

There is an issue with fsevent 1 and nodeJS 14

enter image description here

I recommend you to start by fixing this, and to use the same version of NodeJS on your local environment. The latest cloud builder npm container is node-14 by default(latest)

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
  • Hi, I installed version 14.0.0 as well as 14.10.0 (latest build release) locally and tried the trigger again. However, I receive the same error - IMO it seems like fsevent is not the cause of the error. contextify in relation with node-gyp rebuild looks like the cause... – Maeaex1 Apr 19 '21 at 19:09
  • Before using nodejs14 which version did you use locally? Have you tried it with nodejs12 and making it work locally? It seems to be an issue related with the Node versions conflicting with the packages rather than Cloud Build, so I suggest you to test locally older versions until you make it work before using Cloud Build As @guillaume mentioned the issue is on nodejs 14 so I don't understand why upgrade to that version – Emmanuel May 27 '21 at 00:29