Error: Unknow Dialect Undefined (Strapi/Google App Engine)

System Information
  • Strapi Version: 4.0.2
  • Operating System: Mac
  • Database: pg@8.7.1
  • Node Version: 16.13.1
  • NPM Version:
  • Yarn Version:

Hi all,

Getting this error after following Grand Reality’s tutorial on getting started with Strapi and Google App Engine

“Error: Unknow dialect undefined
at getDialectClass (/workspace/node_modules/@strapi/database/lib/dialects/index.js:12:13)
at getDialect (/workspace/node_modules/@strapi/database/lib/dialects/index.js:19:23)
at new Database (/workspace/node_modules/@strapi/database/lib/index.js:38:20)
at Function.Database.init (/workspace/node_modules/@strapi/database/lib/index.js:84:33)
at Strapi.bootstrap (/workspace/node_modules/@strapi/strapi/lib/Strapi.js:347:30)
at Strapi.load (/workspace/node_modules/@strapi/strapi/lib/Strapi.js:410:16)
at async Strapi.start (/workspace/node_modules/@strapi/strapi/lib/Strapi.js:161:9)”

Any ideas what might be going wrong? Appreciate any insight you might have.

I am getting the same error at Digital Ocean. I will let you know if I figure it out.

const getDialectClass = client => {
  switch (client) {
    case 'postgres':
      return require('./postgresql');
    case 'mysql':
      return require('./mysql');
    case 'sqlite':
      return require('./sqlite');
    default:
      throw new Error(`Unknow dialect ${client}`);
  }
};

where the client is - db.config.connection
So if you have been following previous solutions - which talked about a connections object etc .

module.exports = ({ env }) => ({
  defaultConnection: 'default',
  connections: {
    default: {
      connector: 'bookshelf',
      settings: {
        client: 'postgres',
        host: config.host,
        port: config.port,
        database: config.database,
        username: config.user,
        password: config.password,
        ssl: {
          rejectUnauthorized: false,
        },
      },
      options: {
        ssl: true,
      },
    },
  },
});

db.config.connection would return undefined. & so it would fail

This can be easily resolved by simply changing the database.js file content format to the following:

module.exports = ({ env }) => ({
  connection: {
    client: 'postgres',
    connector: 'bookshelf',
    connection:{
      socketPath: `/cloudsql/${env('INSTANCE_CONNECTION_NAME')}`,
      database: env('DATABASE_NAME'),
      user: env('DATABASE_USERNAME'),
      password: env('DATABASE_PASSWORD'),
    }
  }
});

You might also run into some directory issue which can also be resolved by simply creating an empty .txt file inside database/migrations folder.

Cheers!

If you are starting a Typescript project, you should follow the Start strapi programmatically section in TypeScript | Strapi Documentation , otherwise you have to deploy tsconfig.json file and src and config dirs together with the dist dir to production env if you try to start it with strapi start.

This is because the @strapi/typescript-utils/lib/utils/is-using-typescript uses the tsconfig.json file to determine whether you are starting a Typescript project or a Javascript project when running strapi start.

Hope this helps you guys.

1 Like