I have a nodejs project running on app engine. This worked fine until yesterday. My package.json is also uploaded becuase it contains dependencies and start script. When I deploay a google cloud build is automatically run. Since yesterstay it also tries to run "npm run build". Of course this fails because I don't upload any source files.
I did not configure this and I'm wondering why the behaviour changed.
To upload I use the gcloud comand:
gcloud app deploy --version v1
My app.yml looks like:
# [START app_yaml]
runtime: nodejs16
instance_class: F1
automatic_scaling:
max_instances: 1
entrypoint: npm run cloud-start
handlers:
- url: /api/.*
script: auto
secure: always
- url: /(.*\.(gif|png|jpg|css|js|json)(|\.map))$
static_files: dist/www/\1
upload: dist/www/(.*)(|\.map)
secure: always
expiration: "100d 0h"
- url: /|(.*)|index.html
static_files: dist/www/index.html
upload: dist/www/index.html
expiration: "0d 0h"
secure: always
# [END app_yaml]
.cloudignore:
# Ignore everything
/[!.]*
/.?*
# Except the Cloud Function files we want to deploy
!/package.json
!/package-lock.json
!/dist/**
#!include:.gitignore
I got hit by this today as well, and it took me the whole day to finally figure out.
This is 100% a Google functional change for the gcloud app deploy script for nodejs.
Thankfully, there's a simple workaround below, but first I want to rant and give context: this afternoon when I deployed with a totally minor and unrelated change I received a buildbreaker. Everything worked fine locally, so I tried re-deploying a previous build to the dev environment. It, too, failed.
After researching, I found the same thing you did; an unexpected call to npm build
. After a lot more research, I found the workaround.
It turns out that Google arbitrarily decided a few days ago to start running build
if it exists in package.json
as a fallback when there is no gcp-build
script. Thankfully, including a blank gcp-build
script in package.json
fixes the issue. See below for an example
I never received a notice from google cloud that they were doing this.
I, like you, pre-package my build using the npm build script in my package.json
, then run gcloud deploy
while suppressing the original source folder.
I, like you, did not include a gcp-build
script, because I had no special build needs.
Workaround
Add "gcp-build": ""
to the scripts
section of your package.json
.
Example:
{
"name": "myapp",
"main": "mybuild/index.js",
"scripts": {
"build": "tsc",
"start": "node mybuild/index.js",
"gcp-build": ""
},
}
If there is a gcp-build
command in the scripts section, Google Cloud will try to run that, rather than build
. If it's blank, it will do nothing but most imporantly will not fall back to build
.
Future Reference
This is current information and there is a very good chance google will change this functionality very soon. I will try to keep an eye on developments and update as necessary
update
Looks like google has rolled this out to cloud functions as well.