4

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?

András Geiszl
  • 966
  • 2
  • 16
  • 36
  • Try deploying with `yarn install --ignore-engines` and let me know if it works – Farid Shumbar Sep 28 '21 at 14:35
  • It would probably build, but I checked and the node version on the instance is `12.19.0`, and, e.g. the latest `node-fetch` requires `>=12.20.0`. I wouldn't use a Node version in production, which is not supported officially by the package (even if it seems to work). – András Geiszl Sep 28 '21 at 15:05
  • Why the -1 though? It's a legitimate problem and I detailed many things that I already found out. Should I have posted somewhere else? – András Geiszl Oct 05 '21 at 16:24
  • Can you try to delete the Node version specification from the `package.json` Engine section? Does it work? – Farid Shumbar Oct 13 '21 at 12:31
  • I tried it. It builds successfully, but when I SSH into the instance and check the node version in still says `v12.19.0`. – András Geiszl Oct 13 '21 at 15:03
  • I also reported the bug on the issue tracker, you can see the full build log there: https://issuetracker.google.com/issues/202515249 – András Geiszl Oct 13 '21 at 15:05

3 Answers3

3

I encountered the same issue and created an issue for it here. I suspect it is a bug with Google App Engine and not with your app.

As a workaround, I ended up using a custom runtime for my app. To do this, in your GAE configuration file you switch from runtime: nodejs to runtime: custom and add a Dockerfile to your project root. There are good docs on writing a dockerfile here but here is a simple one you can use:

# syntax=docker/dockerfile:1

FROM node:14.10.0
ENV NODE_ENV=production

WORKDIR /app

COPY ["package.json", "package-lock.json*", "./"]

RUN npm install --production

COPY . .

CMD [ "node", "server.js" ]

You'll probably also want a .dockerignore file that at least contains node_modules.

Ultimately I think a GAE fix would be nicer, since it would be simpler to just configure your node version in package.json, like you're supposed to be able to. But this should be enough to get things working and sidestep what appears to be a GAE bug.

Charlie A
  • 416
  • 3
  • 11
1

To wrap it up, as @CharlieA mentioned, App Engine Flex environment has a default image for Node.js which is currently version 12.19.01.

As @Cleanbeans pointed out, according to the Flex environment docs, the runtime for Node.js should be specified in the app.yaml as runtime: nodejs, unile other languages where you can specify the version number. This explains why the Engine was returning the default version despite specifying the version 14.

Circling back to @CharlieA comment, this can be fixed by using the custom runtime in your app.yaml as follows: runtime: custom.

Alternatively, try using a fixed version in your package.json as being discussed in this Github thread.

Apart from the Github thread mentioned above, @CharlieA also created a Public Issue tracker for Google to review this. You may want to request a documentation update that would elaborate on how to specify the Node.js version in the Flexible environment.

Farid Shumbar
  • 1,360
  • 3
  • 10
  • Specifying a fixed runtime version didn't work for me either. I think that GitHub thread is a slightly different issue than what we are discussing here. – András Geiszl Dec 09 '21 at 14:33
0

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

Cleanbeans
  • 655
  • 4
  • 12
  • Thanks for your answer. I believe the `nodejs14` value for the `runtime` is only for App Engine Standard. But to be sure I also tried to change that, updated `engines.node` to `14.x`, even reinstalled the local Node to be the latest `v14` and got `ERROR: (gcloud.app.deploy) Your application does not satisfy all of the requirements for a runtime of type [nodejs14].`. After changing the runtime back to `nodejs`, it gave me the same error `error @bindr/dev@1.0.0: The engine "node" is incompatible with this module. Expected version "14.x". Got "12.19.0"` – András Geiszl Oct 06 '21 at 08:13
  • I've had similar problems with `Firebase`. Sometimes the GCloud api caches certain attributes to later use them. I remember `Firebase Deploy` had a similar effect for me. I think I had to delete any cached file's relating to Firebase in order to solve this. Try at least logging out of `GCloud SDK` and logging back in again. This may just be a simple issue. – Nizar Oct 08 '21 at 16:37
  • Thanks for the suggestion. I tried revoking the access, then logging in again, I even tried deploying it to a different project, but none of these worked. – András Geiszl Oct 09 '21 at 16:48