-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect reference to __dirname when compiling to esmodules #1167
Comments
This should be catchable with a lint rule |
What do you mean? |
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: