MikroORM 无法连接到我的 PostgreSQL 服务器,出现错误:throw new ERR_INVALID_ARG_TYPE

问题描述

这是控制台:

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...

我不知道该怎么办,请帮忙:c

顺便说一句,我正在学习 Ben Awad 的 14 小时全栈教程 我的 Postgresql 服务器看起来不错,我知道可能是什么问题,但如果你什么都没有,请告诉它

解决方法

您有受密码保护的 postgres 实例,但您没有提供密码。

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;

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