Still having problems with db-migrate and ESM node projects...
See original GitHub issueI’m submitting a…
- Bug report
- Feature request
- Question
Current behavior
I’m still having trouble running db-migrate in an ESM project / module (on the latest beta 1.0.0-beta.18). I keep receiving this error:
[ERROR] Error [ERR_REQUIRE_ESM]: require() of ES Module /home/kyle/web/server/migrations/some-migration.js from /home/kyle/web/server/node_modules/db-migrate/lib/file.js not supported. Instead change the require of some-migration.js in /home/kyle/web/server/node_modules/db-migrate/lib/file.js to a dynamic import() which is available in all CommonJS modules.
Minimal reproduction of the problem with instructions
My migration file looks something like this:
const Table = require('../dist/database/tables/SomeTable.js').SomeTable;
const table = new Table();
...
exports.up = function (db) {
return table.up(db);
};
...
I’ve also tried swapping the first line for something like this:
import {SomeTable} from '../dist/database/tables/SomeTable.js';
...
but neither have worked. Does it have something to do with me importing a file into the migration file? The imported table is from an ESM module that also has dependencies to other ESM (local) projects.
I’ve recently switched my projects to ESM, so let me know if I’m missing something.
Environment
db-migrate version: 1.0.0-beta.18
plugins with versions: none
db-migrate driver with versions: db-migrate-mysql 2.2.0
Additional information:
- Node version: 16.16.0
- Platform: Ubuntu Server 18.04.6
Related Links
#721 & #784 Supposedly solved in #724
Edit: Code blocks
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
b/c this has nothing to do with us. We support for db-migrate, not for understanding nodejs.
as a little favor:
https://nodejs.org/api/esm.html#interoperability-with-commonjs https://pencilflip.medium.com/using-es-modules-with-commonjs-modules-in-node-js-1015786dab03
Well please read the models docs about esmodules for that.
Sent from Nine
–
Best
– Tobias Gurtzick CEO WizardTales GmbH
Additional Contacts: @github | @.***
Website: https://www.wizardtales.com @.*** nmlpm: – coming soon & open source –
Please tag your mails with “request”, “issue” or “proposal”, unless none of these fit or there already exists a thread.
– Why should one reach for what one may be capable reaching, that’s awfully boring and after all one still be ones yesterday being. –
Sitz der Gesellschaft: Ratingen Kokkolastr. 5 40882 Ratingen Germany
Registergericht: Amtsgericht Düsseldorf, HRB 84140 Geschäftsführer: Tobias Gurtzick
Von: Kyle Elmore @.***> Gesendet: Samstag, 23. Juli 2022 17:57 An: db-migrate/node-db-migrate Cc: Tobias Gurtzick; State change Betreff: Re: [db-migrate/node-db-migrate] Still having problems with db-migrate and ESM node projects… (Issue #794)
Thanks for the quick response. However, I’m still getting the same error even with the package.json file in the migrations folder Now, if my migration file looks like this:
const Table = require(‘…/dist/database/tables/SomeTable.js’).SomeTable; const table = new Table();
…
exports.up = function (db) { return table.up(db); };
…
I get the same error as above (Error [ERR_REQUIRE_ESM]) But if my migration file looks like this:
import {SomeTable} from ‘…/dist/database/tables/SomeTable.js’; …
I get this error:
[ERROR] unhandledRejection [ERROR] /home/kyle/web/EbayServer/migrations/some-migration.js:3 import {SomeTable} from ‘…/dist/database/tables/SomeTable.js’; ^^^^^^
SyntaxError: Cannot use import statement outside a module
Is there something else I need to do? Thanks! — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you modified the open/close state.Message ID: @.***>