Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ben Awad vid tutorial problemwith npx mikro-orm migration:create

I'm following the tutorial step by step, when I get to the part of run npx mikro-orm migration:create, I get this error

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:113:9)
    at Object.createHmac (crypto.js:147:10)
    at createHMAC (C:\lireddit-server\node_modules\pg\lib\sasl.js:133:17)
    at Hi (C:\lireddit-server\node_modules\pg\lib\sasl.js:137:13)
    at Object.continueSession (C:\lireddit-server\node_modules\pg\lib\sasl.js:32:24)
    at Client._handleAuthSASLContinue (C:\lireddit-server\node_modules\pg\lib\client.js:248:10)
    at Connection.emit (events.js:314:20)
    at Connection.EventEmitter.emit (domain.js:483:12)
    at C:\lireddit-server\node_modules\pg\lib\connection.js:109:12
    at Parser.parse (C:\lireddit-server\node_modules\pg-protocol\src\parser.ts:102:9)
    at Socket.<anonymous> (C:\lireddit-server\node_modules\pg-protocol\src\index.ts:7:48)
    at Socket.emit (events.js:314:20)
    at Socket.EventEmitter.emit (domain.js:483:12)
    at addChunk (_stream_readable.js:298:12)
    at readableAddChunk (_stream_readable.js:273:9)```

I can't find any solution on google, and the tut doesn't point out how to login to postgresql on the app
like image 864
Alejandro Rdz Avatar asked Mar 25 '26 04:03

Alejandro Rdz


2 Answers

You are missing some configuration, most probably user or password fields. Here is related issue:

https://github.com/mikro-orm/mikro-orm/issues/866

If you do not provide them, MikroORM will pick the defaults for given driver, which is postgres user and empty password - your postgres installation apparently do not have empty password for this user.

If you are using docker to create the postgres server, this is how you can make it accept empty pws:

  postgre:
    image: postgres:12.4
    ports:
      - 5432:5432
    environment:
      POSTGRES_HOST_AUTH_METHOD: trust   <-- here
like image 105
Martin Adámek Avatar answered Mar 27 '26 18:03

Martin Adámek


It seems like you have not specified the password or user property of an object which you are passing inside of MikroORM.init.

This should work

export default {
  entities: [Entity],
  dbName: "yourDatabaseName",
  type: "postgresql",
  user: "yourUserName",
  password: "yourPassword"
} as Parameters<typeof MikroORM.init>[0];
like image 20
Alexander Borisov Avatar answered Mar 27 '26 18:03

Alexander Borisov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!