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.