Search code examples
postgresqlmikro-orm

MikroORM not connect to my PostgreSQL server, with an error: throw new ERR_INVALID_ARG_TYPE


Here is the console:

P:\.Projektek\lireddit-server>yarn dev
    yarn run v1.22.10
    $ nodemon dist/index.js
    [nodemon] 2.0.7
    [nodemon] to restart at any time, enter `rs`
    [nodemon] watching path(s): *.*
    [nodemon] watching extensions: js,mjs,json
    [nodemon] starting `node dist/index.js`
    [discovery] ORM entity discovery started, using ReflectMetadataProvider
    [discovery] - processing entity Post
    [discovery] - entity discovery finished, found 1 entities, took 29 ms
    internal/crypto/keys.js:322
        throw new ERR_INVALID_ARG_TYPE(
        ^
    
    TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be of type string or an instance of Buffer, TypedArray, DataView, or KeyObject. Received null
        at prepareSecretKey (internal/crypto/keys.js:322:11)
        at new Hmac (internal/crypto/hash.js:111:9)
        at Object.createHmac (crypto.js:147:10)
        at createHMAC (P:\.Projektek\lireddit-server\node_modules\pg\lib\sasl.js:133:17)
        at Hi (P:\.Projektek\lireddit-server\node_modules\pg\lib\sasl.js:137:13)
        at Object.continueSession (P:\.Projektek\lireddit-server\node_modules\pg\lib\sasl.js:32:24)
        at Client._handleAuthSASLContinue (P:\.Projektek\lireddit-server\node_modules\pg\lib\client.js:257:10)       
        at Connection.emit (events.js:315:20)
        at Connection.EventEmitter.emit (domain.js:467:12)
        at P:\.Projektek\lireddit-server\node_modules\pg\lib\connection.js:115:12 {
      code: 'ERR_INVALID_ARG_TYPE'
    }
    [nodemon] app crashed - waiting for file changes before starting...

I don't know what to do, plz help :c

Btw im doin Ben Awad's fullstack 14 hour long tutorial My Postgresql server looks fine, idk what can be the problem, but if you no anything plz tell it


Solution

  • You have password protected postgres instance but you are not providing the password.

    import { Options } from '@mikro-orm/core';
    
    const config: Options = {
      migrations: {
        path: path.join(__dirname, "./migrations"), // path to the folder with migrations
        pattern: /^[\w-]+\d+\.[tj]s$/, // regex pattern for the migration files       
      },
      entities: [Post],
      dbName : 'lireddit',
      type: 'postgresql',
      password: "s3xy",
      debug: !__prod__,
    };
    
    export default config;
    

    Source: https://github.com/mikro-orm/mikro-orm/issues/866#issuecomment-720791720