Typescript migrations doesn't work
What you are doing?
I have migrations written in typescript. These compiled worked fine until CLI of version 6.1.0. They don't after updating to version 6.4.1.
npx sequelize db:migrate --env development
What is actually happening?
ERROR: Cannot use import statement outside a module
Dialect: mysql Database version: 5.7 Sequelize CLI version: 6.4.1 Sequelize version: 6.15.1
What does your TypeScript transpilation setup look like? Do you transpile your TS migrations to JS before running them?
It may be caused by this PR https://github.com/sequelize/cli/pull/915/, which loads TypeScript files but, unless ts-node is used, will treat them as plain JavaScript. IMO that PR should be rolled back and we should instead provide a way to configure which file extensions will be loaded & document how to use with ts-node.
What does your TypeScript transpilation setup look like? Do you transpile your TS migrations to JS before running them?
Yep, I do (as it was necessary before the typescript was supported).
Does your build output include both .ts (or .d.ts) & .js files? If so that's definitely caused by this PR.
Yes, it does. But it fails also if I remove .js files (exclude form TS compilation).
It's the .ts files that should be removed from the build output. At least until we have a solution
IMO that PR should be rolled back and we should instead provide a way to configure which file extensions will be loaded & document how to use with ts-node.
Hey @ephys, any progress in here?☝🏻
Summoning also @WikiRik, @sdepold, @sushantdhiman as you are probably the last active contributor here and "feat: support migrations files with ts file extension" is not actually true.
Hey @ephys, any progress in here?☝🏻
Unfortunately my work on the CLI is limited to issue and PR review as the time I can donate to this project is limited and my focus is on the main library.
Hopefully someone else is willing to maintain the CLI :/
As for your issue, I think that if you remove the .ts files from your build output, and only keep the transpiled .js files there, it should work.
As for your issue, I think that if you remove the .ts files from your build output, and only keep the transpiled .js files there, it should work.
Yep, but it doesn't actually mean TS migrations are supported. 🙂
@andrejleitner did you find a solution to this issue?
I still transpile .ts to .js myself.
I too am facing the same error and use a different migrations directory to get around this problem
Hi! I am too facing same issue 🆙 Workaround in build process to copy the migrations to different dir, and run the migrations from that directory - settting in .sequalizer