GoogleCloudPlatform / nodejs-docker

The Node.js Docker image used by Google App Engine Flexible.
https://cloud.google.com/nodejs
Apache License 2.0
405 stars 115 forks source link

The engine "node" is incompatible with this module #233

Open ishak-lm opened 2 years ago

ishak-lm commented 2 years ago

Following this issue https://stackoverflow.com/questions/72052616/google-app-engine-the-engine-node-is-incompatible-with-this-module and this one too https://github.com/GoogleCloudPlatform/nodejs-docker/issues/214, we still have an issue with the Node version.

This questions has been asked many times already, and I checked all the answers but none of them helped me.

I'm trying to deploy a NodeJs app to GAE using a app.yml file. It was working perfectly until my last Github PR on it where I upgraded some nodes modules.

Now I'm getting the Error The engine "node" is incompatible with this module. Expected version "16.x.x". Got "12.19.0".

As you can see I'm up to date on my computer. I also removed and install Node, Npm and Yarn tonight just to be sure.

node -v
v16.15.0
npm -v
8.5.5
yarn -v
1.22.18

I tried deploying the app with a specific node version on my packages.json but with or without it's not working.

  "engines": {
    "node": "16.x.x"
  },

I also tried to remove the cache on GAE using this, without no effect.

default_expiration: '0d 0h'

On my app.yml I'm using nodejs en Env: flex:

runtime: nodejs
env: flex

I can't use node16 as I need env: flex.

Of course I tried to delete the Node_modules and yarn.lock for at least 100 times but still nothing, always the same error.

Nothing change on the app.yml file since the last deployment. The only thing is that I upgraded some Node Modules.

On the Yarn side I've tried:

yarn install --force
yarn install --ignore-engines
yarn cache clean --all

But still not working.


# [START app_yaml]
runtime: custom
env: flex

# default_expiration: '0d 0h'

# Define environment variable
env_variables:
  # NodeJS
  NODE_ENV: 'prod'
  APP_PORT: 8080

beta_settings:
  # The connection name of your instance, available by using
  # 'gcloud beta sql instances describe [INSTANCE_NAME]' or from
  # the Instance details page in the Google Cloud Platform Console.
  cloud_sql_instances: '********'
# Resources configuration (for each server)
resources:
  cpu: 1
  memory_gb: 2
  disk_size_gb: 10
# Configuration of automatic scaling
automatic_scaling:
  min_num_instances: 1
  max_num_instances: 3
  cool_down_period_sec: 180
  cpu_utilization:
    target_utilization: 0.6
# [END app_yaml]

Any help will be really grateful.

OleksiiKachan commented 2 years ago

same issue here I believe the issue is here in the base dockerfile

RUN /opt/gcp/runtime/bootstrap_node \
    --direct \
    v12.19.0
jinglundong commented 2 years ago

Sorry, I lost track of this issue. Yes, v12.19.0 is configured in that base dockerfile. However, I couldn't reproduce this issue.

I was able to install node 16, with the following logs from cloud build:

Step #2: INFO[0023] COPY . /app/                                 
Step #2: INFO[0023] Taking snapshot of files...                  
Step #2: INFO[0023] RUN /usr/local/bin/install_node '16.17.1'    
Step #2: INFO[0023] cmd: /bin/sh                                 
Step #2: INFO[0023] args: [-c /usr/local/bin/install_node '16.17.1'] 

This is different from builds failures reported here:

Step #2: INFO[0024] COPY . /app/                                 
Step #2: INFO[0024] RUN NODE_ENV=*********** yarn install ||   ((if [ -f yarn-error.log ]; then       cat yarn-error.log;     fi) && false) 
Step #2: INFO[0024] cmd: /bin/sh                                 
Step #2: INFO[0024] args: [-c NODE_ENV=*********** yarn install ||   ((if [ -f yarn-error.log ]; then       cat yarn-error.log;     fi) && false)]
Step #2: yarn install v1.22.19
Step #2: [1/5] Validating package.json...
Step #2: error *************-api@1.0.0: The engine "node" is incompatible with this module. Expected version "16.17.1". Got "12.19.0"
Step #2: error Found incompatible module

I spent some time today, and realized that https://github.com/GoogleCloudPlatform/nodejs-docker/blob/9bf092153574f62b650f982d5505b8b9f3d83469/builder/steps/gen-dockerfile/contents/data/Dockerfile.txt#L5-L6 might be part of the puzzle. NODE_ENV=*********** in the log seems to be NODE_ENV= development. Because the other option "production" actually has one less "*". We will continue the investigation tomorrow.

kennethye1 commented 2 years ago

Taking a closer look

if (packageJson.scripts) {
      hasBuildCommand = BUILD_SCRIPT_NAME in packageJson.scripts;
}

Not including gcp-build in scripts should ignore the RUN NODE_ENV=*********** yarn install || ((if [ -f yarn-error.log ]; then part. However need to figure out what fixes are needed for this if user needs a build command.

jinglundong commented 2 years ago

Good point. I missed that first if statement in that template and thought it's always true. (Blaming the two COPY . /app/ statements in the template file https://github.com/GoogleCloudPlatform/nodejs-docker/blob/9bf092153574f62b650f982d5505b8b9f3d83469/builder/steps/gen-dockerfile/contents/data/Dockerfile.txt#L3 😏 .)

Yes, https://github.com/GoogleCloudPlatform/nodejs-docker/blob/93ded4fc7a62c4b491cad302b5d8fa8d489a8b49/builder/steps/gen-dockerfile/contents/src/detect_setup.ts#L213 is checking if string "gcp-build" is in the "scripts" property (https://classic.yarnpkg.com/lang/en/docs/package-json/#toc-scripts) of the package.json file.

I will try to reproduce this.

jinglundong commented 2 years ago

Okay, I triggered an error (not exactly the same yet), by changing my package.json file. This newly added "gcp-build" triggered the bug.

"scripts": { "start": "node app.js", "test": "mocha --exit test/*.test.js", "gcp-build": "hello" },

Kenneth's fix https://github.com/GoogleCloudPlatform/nodejs-docker/pull/258 looks promising to me.

jinglundong commented 2 years ago

Status update: we are releasing Kenneth's fix #258 .

kennethye1 commented 2 years ago

Unfortunately #260 caused #261