I'm trying to deploy a GCloud App Engine Flexible service. I have a yaml file, in which it has the Node.js runtime and the env
specified.
runtime: nodejs
env: flex
As the documentation says "You can specify a different Node.js version in your application's package.json file by using the engines field.", I also added the following to package.json
:
"name": "@bindr/dev",
"version": "1.0.0",
"engines": {
"node": ">=14.0.0"
},
However, when I run gcloud app deploy
, I get the following error:
error @bindr/dev@1.0.0: The engine "node" is incompatible with this module. Expected version ">=14.0.0". Got "12.19.0"
It seems like the deployment process doesn't take the engines
property into account, because even if I specify an invalid version (e.g. >=18.0.0
) it still doesn't complain, only the yarn install
fails. How can I make the build process use the specified Node version?
I found that I could specify the version of Node in cloudbuild.yaml
for the certain steps of the build, like so:
steps:
- name: node:node-14.10.0
args: ['predeploy.js', 'content-server']
- name: 'gcr.io/cloud-builders/yarn:node-14.17.1'
args: ['install']
- name: 'gcr.io/cloud-builders/gcloud'
args: ['app', 'deploy']
timeout: '900s'
In this process, the yarn install
step succeeds, but the gcloud app deploy
step still fails while trying to install the dependencies (I couldn't find how I could specify the node version to gcr.io/cloud-builders/gcloud
, it doesn't seem to be such tag).
I also checked and the same 12.19.0
version is running on the production instances, so it is not only the build environment that has an older version.
What am I doing wrong?
CodePudding user response:
So take a look at this doc, with particular attention to this line
The engines.node property is optional, but if present, the value must be compatible with the Node.js version specified in your app.yaml file. For example:
I believe the default version is 12 (i.e. runtime: nodejs
) to correct this in your app.yaml
file set runtime as follows runtime: nodejs14
or newer
Also bear in mind that minor patches are updated automatically so you can only specify the major version i.e. 14.X.X. Additionally if your stated version is not available the build process will fail.
Note: If you are using cloud build with cloudbuild.yaml
and a flex environment you may get a build error, move cloudbuild.yaml
into its own folder to prevent this error and use --config option to state the location of the yaml. See this doc for further guidance
CodePudding user response:
Seems like your local node version is 12.19.0 and the deployment won't succeed until you upgrade your local version as well.