You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running the migrations using the Programmatic API, the node-pg-migrate source has a reference to __dirname which is not available when using ES modules.
Steps to reproduce
When running the migrations using the Programmatic API using ES modules as follows:
Error: Can't get migration files: ReferenceError: __dirname is not defined
Looking at the source file, it looks like there is a reference to __dirname, which is only accessible using CommonJS modules.
Logs
Error: Can't get migration files: ReferenceError: __dirname is not defined
at file:///path/to/project/node_modules/node-pg-migrate/dist/esm/index.mjs:2579:115
at Array.map ()
at loadMigrations (file:///path/to/project/node_modules/node-pg-migrate/dist/esm/index.mjs:2577:13)
at async Promise.all (index 0)
at async runner (file:///path/to/project/node_modules/node-pg-migrate/dist/esm/index.mjs:2763:36)
at async initialiseDatabase (file:///path/to/project/dist/infrastructure/postgres/index.mjs:19:9)
at async file:///path/to/project/dist/index.mjs:13:26
at loadMigrations (file:///path/to/project/node_modules/node-pg-migrate/dist/esm/index.mjs:2601:11)
at async Promise.all (index 0)
at async runner (file:///path/to/project/node_modules/node-pg-migrate/dist/esm/index.mjs:2763:36)
at async initialiseDatabase (file:///path/to/project/dist/infrastructure/postgres/index.mjs:19:9)
at async file:///path/to/project/dist/index.mjs:13:26
What do you mean? __dirname is legit in node-pg-migrate's codebase cause it was historically fully written only with cjs in mind.
Everything here is valid and over in #1168 we are already working on a fix.
However, we need to ensure compatibility to cjs and esm for the same time to ensure a smooth migration between major versions.
Ah right, since it needs to support both, then just banning one style or the other doesn’t make as much sense.
That said as a pattern I’ve had some success in other contexts using linting as a detection tool - ban both patterns, but then selectively add lint ignore comments with explanations ensure that the places where the library does need to use them have been exhaustively audited.
That lets the tooling guide us to detect missed cases and avoid regressions.
Describe the bug
When running the migrations using the Programmatic API, the
node-pg-migrate
source has a reference to__dirname
which is not available when using ES modules.Steps to reproduce
When running the migrations using the Programmatic API using ES modules as follows:
The following error is returned:
Looking at the source file, it looks like there is a reference to __dirname, which is only accessible using CommonJS modules.
Logs
Error: Can't get migration files: ReferenceError: __dirname is not defined
at file:///path/to/project/node_modules/node-pg-migrate/dist/esm/index.mjs:2579:115
at Array.map ()
at loadMigrations (file:///path/to/project/node_modules/node-pg-migrate/dist/esm/index.mjs:2577:13)
at async Promise.all (index 0)
at async runner (file:///path/to/project/node_modules/node-pg-migrate/dist/esm/index.mjs:2763:36)
at async initialiseDatabase (file:///path/to/project/dist/infrastructure/postgres/index.mjs:19:9)
at async file:///path/to/project/dist/index.mjs:13:26
at loadMigrations (file:///path/to/project/node_modules/node-pg-migrate/dist/esm/index.mjs:2601:11)
at async Promise.all (index 0)
at async runner (file:///path/to/project/node_modules/node-pg-migrate/dist/esm/index.mjs:2763:36)
at async initialiseDatabase (file:///path/to/project/dist/infrastructure/postgres/index.mjs:19:9)
at async file:///path/to/project/dist/index.mjs:13:26
System Info
Used Module System
esm
The text was updated successfully, but these errors were encountered: