atdatabases
atdatabases copied to clipboard
pg-migrations with TypeScript migrations from esm only package fails to import
I am trying to import a module from an esm
package. My project is in itself an esm
package. I am getting following error
Error [ERR_REQUIRE_ESM]: require() of ES Module <package_file> from src/migrations/0001-init.ts not supported.
package.json
of the imported package is as follows
"type": "module",
"main": "./dist/index.js",
"exports": {
".": "./dist/index.js",
"./*": "./dist/*.js"
},
"typesVersions": {
"*": {
"*": ["dist/*"]
}
},
migration project itself is a esm
package containing type: module
in its package.json
I am running the pg-migration using following cli
pg-migrations apply -D src/migrations -c <connection_string>
If I remove type: module
from the package.json
of imported package, then it all works.
Would anyone have any workaround for this.
I think the only option where would be to use .mjs
for your modules, instead of relying on "type": "module"
in package.json
. I don't think there's any obvious way to make pg-migrations work with both CommonJS and ESModules at the same time.