最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Deployment error on Google App Engine: "error: con.connect is not a function" - Stack Overflow

programmeradmin8浏览0评论

I'm new on Strapi Cloud and Google Cloud. I have tried to deploy my Strapi Cloud app by using Google App Engine, and I followed a website/videos (/strapi-cms-on-google-cloud-platform-the-definitive-guide-part-1?source=more_series_bottom_blogs).

The Strapi seems to have been deployed successfully.

Deployment succeeded on Terminal

However, when opening the URL, it has shown: The browser didn't show the Strapi admin page.

my logs have shown:

2025-02-05 06:24:00 default[xxxxxxxxxxxxxxx]  "GET / HTTP/1.1" 503
2025-02-05 06:24:09 default[xxxxxxxxxxxxxxx]  [2025-02-05 06:24:09.556] error: con.connect is not a function
2025-02-05 06:24:09 default[xxxxxxxxxxxxxxx]  TypeError: con.connect is not a function      at Client._connect (/workspace/node_modules/pg/lib/client.js:112:11)      at /workspace/node_modules/pg/lib/client.js:166:12      at new Promise (<anonymous>)      at Client.connect (/workspace/node_modules/pg/lib/client.js:165:12)      at Client_PG._acquireOnlyConnection (/workspace/node_modules/knex/lib/dialects/postgres/index.js:91:23)      at Client_PG.acquireRawConnection (/workspace/node_modules/knex/lib/dialects/postgres/index.js:99:17)      at create (/workspace/node_modules/knex/lib/client.js:262:39)
2025-02-05 06:24:09 default[xxxxxxxxxxxxxxx]  [2025-02-05 06:24:09.557] info: Shutting down Strapi
2025-02-05 06:24:10 default[xxxxxxxxxxxxxxx]  "GET /favicon.ico HTTP/1.1" 503
2025-02-05 06:24:16 default[xxxxxxxxxxxxxxx]  [2025-02-05 06:24:16.575] error: con.connect is not a function
2025-02-05 06:24:16 default[xxxxxxxxxxxxxxx]  TypeError: con.connect is not a function      at Client._connect (/workspace/node_modules/pg/lib/client.js:112:11)      at /workspace/node_modules/pg/lib/client.js:166:12      at new Promise (<anonymous>)      at Client.connect (/workspace/node_modules/pg/lib/client.js:165:12)      at Client_PG._acquireOnlyConnection (/workspace/node_modules/knex/lib/dialects/postgres/index.js:91:23)      at Client_PG.acquireRawConnection (/workspace/node_modules/knex/lib/dialects/postgres/index.js:99:17)      at create (/workspace/node_modules/knex/lib/client.js:262:39)
2025-02-05 06:24:16 default[xxxxxxxxxxxxxxx]  [2025-02-05 06:24:16.576] info: Shutting down Strapi

I have no idea what the error means. My configurations are as below:

The backend(Strapi Cloud) file structure

/backend/app.yaml

runtime: nodejs20
env: standard
instance_class: F2

env_variables:
  HOST: '0.0.0.0'
  NODE_ENV: 'production'
  DATABASE_NAME: 'postgres'
  DATABASE_USER: 'postgres'
  DATABASE_PASSWORD: 'xxxxxxxxxxx'
  INSTANCE_CONNECTION_NAME: 'xxxxxxxxxxx:australia-southeast1:strapi'
  GCS_BUCKET_NAME: 'xxxxxxxxxxx'
  GCS_BASE_PATH: 'cms'

beta_settings:
  cloud_sql_instances: 'xxxxxxxxxxx:australia-southeast1:strapi'

/backend/config/env/production/database.js

const path = require('path');

module.exports = ({ env }) => ({
    connections: {
        client: "postgres",
        connection: {
            host: `/cloudsql/${env('INSTANCE_CONNECTION_NAME')}`,
            database: env('DATABASE_NAME'),
            user: env('DATABASE_USER'),
            password: env('DATABASE_PASSWORD'),
            tmp: path.resolve('/tmp'),
        },
    },
});

/backend/config/database.js

module.exports = ({ env }) => {
  const client = env('DATABASE_CLIENT', 'postgres');

  const connections = {
    postgres: {
      connection: {
        client: 'postgres',
        connection: {
          host: env('DATABASE_HOST', '127.0.0.1'),
          port: env.int('DATABASE_PORT', 5432),
          database: env('DATABASE_NAME', 'postgres'),
          user: env('DATABASE_USERNAME', 'postgres'),
          password: env('DATABASE_PASSWORD'),
          ssl: env.bool('DATABASE_SSL', true),
        },
        pool: { min: env.int('DATABASE_POOL_MIN', 2), max: env.int('DATABASE_POOL_MAX', 350) },
      },
    },
  };

  return {
    connection: {
      client,
      ...connections[client],
      acquireConnectionTimeout: env.int('DATABASE_CONNECTION_TIMEOUT', 600000),
    },
  };
};

/backend/.env

HOST=0.0.0.0
PORT=1337
VITE_PORT=5175

APP_KEYS=xxxxxxxxxxxxxxxxxxxx
API_TOKEN_SALT=xxxxxxxxxxxxxxxxxxxx
ADMIN_JWT_SECRET=xxxxxxxxxxxxxxxxxxxx
TRANSFER_TOKEN_SALT=xxxxxxxxxxxxxxxxxxxx
JWT_SECRET=xxxxxxxxxxxxxxxxxxxx

DATABASE_URL=postgres://postgres:[email protected]:5432/strapi
DATABASE_NAME=postgres
DATABASE_USER=postgres
DATABASE_PASSWORD="xxxxxxxxxxxxxxxxxxxx"
DATABASE_HOST=xx.xxx.xx.xxx #public IP address
DATABASE_CLIENT=postgres

INSTANCE_CONNECTION_NAME=xxxxxxxxxxxxxxxxxxxx:australia-southeast1:strapi
GCS_BUCKET_NAME=xxxxxxxxxxxxxxxxxxxx
GCS_BASE_PATH=cms

CLOUD_SQL_PASSWORD="xxxxxxxxxxxxxxxxxxxx"
CLOUD_SQL_CONNECTION_NAME=xxxxxxxxxxxxxxxxxxxx:australia-southeast1:strapi
CLOUD_STORAGE_BUCKET_NAME=xxxxxxxxxxxxxxxxxxxx

Expectation: The browser should show the Strapi admin page

What I have been done

  • Change the default client with "postgres"
  • Change the status of "DATABASE_SSL" with "true"
  • Cannot find "con.connect" function in my files
发布评论

评论列表(0)

  1. 暂无评论