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
Migrations that use ESM format can't run via the migrations API #5323
Comments
Any solution or workaround on this? |
Usually "Uncaught SyntaxError: Cannot use import statement outside a module" means you'll need |
Happened to stumble on this while testing migration to vitest. This was a dealbreaker so stayed with jest
Does not work with vitest and typescript. After changing |
@jukkaleh-atoz if you're using ts (with inline types) AND modules, you'll need to pass everything through either babel or ts-node. I'm not sure how to do that. However, if you're using "typescript" where you aren't using the types (or using |
@Naddiseo transpiler worked when package.json type was not set to module. I was using vitest to with babel preset so that might have something to with it
|
Same problem here. Now all my tests run on vitest except my db integration tests 😣 |
I have same issues, here is an alternative with good typescript support. |
You also might be able to get away running the process with For CLI migrations (not what OP wanted) I've got typescript ESM migrations working here and you might be able to adapt it to work with programmatic migrations |
Another one here with the same problem. I can run migrations from the CLI, however, if I call knex migrations from the test it throws:
If I do that then the project starts breaking down. I am going to give Jest a try because I am using vitest. |
Similar issue here: we replaced our testing framework
Has anyone found a solution yet? |
When running migrations programatically (as part of integration test setup) we ended up switching from beforeAll(async () => {
await new Promise((resolve, reject) => {
const p = spawn('yarn', ['knex', 'migrate:latest', '--env', 'local']);
p.on('close', resolve);
p.on('error', reject);
});
}); |
Environment
Knex version: latest
Database + version: PostgreSQL latest
OS: linux
Bug
When trying to run knex.migrate() (programmatically using migrations API NOT via CLI ) on migrations that use ES6 ESM import/export (migrations generated with -x ts) you get "Uncaught SyntaxError: Cannot use import statement outside a module" (This is not a Typescript issue but a ES6 ESM issue ). These migrations do work in the CLI.
"Uncaught SyntaxError: Cannot use import statement outside a module"
Thank you
The text was updated successfully, but these errors were encountered: