sequelize / umzug

Framework agnostic migration tool for Node.js
MIT License
2.01k stars 158 forks source link

TypeError: The "original" argument must be of type function. Received undefined #651

Closed kodelio closed 6 months ago

kodelio commented 6 months ago

Hello,

I'm trying to run migrations, and while locally I have no error, I get this error on the deployment server :

TypeError: The "original" argument must be of type function. Received undefined
    at promisify (node:internal/util:410:3)
    at Object.<anonymous> (/usr/src/app/node_modules/umzug/src/umzug.ts:26:28)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Object.require.extensions.<computed> [as .js] (/home/node/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1608:43)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Here's my code :

migrate.ts

import { umzug } from './umzug-wrapper'
// eslint-disable-next-line import/newline-after-import
;(async () => {
  await umzug.up()
})()

umzug-wrapper.ts

import { SequelizeStorage, Umzug } from 'umzug'

import { sequelizeInstance } from '../../../infrastructure/dependencies/dependencies-repositories'

export const umzug = new Umzug({
  migrations: { glob: `${__dirname}/../migrations/*.[jt]s` },
  create: {
    folder: `${__dirname}/../migrations/`,
  },
  context: sequelizeInstance.sequelize.getQueryInterface(),
  storage: new SequelizeStorage({ sequelize: sequelizeInstance.sequelize }),
  logger: console,
})

I cannot find what is throwing this error

kodelio commented 6 months ago

Issue is apparently caused by having a glob package version > 10

WikiRik commented 6 months ago

This package normally ships with glob version 8. Version 9 of glob includes a big rewrite and only offers support for Node 16 and higher, while umzug v3 supports Node 12 and higher.

Do you not have glob v8 installed?

kodelio commented 6 months ago

@WikiRik we have glob 10.3.10 installed (because required by other packages)

WikiRik commented 6 months ago

Did you override glob to only install 10.3.10? Because it's a defined dependency for umzug it should normally also install glob v8

mmkal commented 6 months ago

@kodelio could you share your setup - which package manager are you using? npm, yarn, pnpm, bun? As well as which version + are you using any overrides, .pnpmfile.cjs etc.?

And/or if you can share your whole package.json that'd be even better. It doesn't sound like a bug in umzug, but maybe we can help.

kodelio commented 6 months ago

Issue has been fixed by adding glob 10.3.10 in the package.json, thank you