cli icon indicating copy to clipboard operation
cli copied to clipboard

.sequelizerc no longer accept .ts extension for config

Open luunguyenbk opened this issue 2 years ago • 5 comments

What you are doing?

I have a .ts config for database connection which used to work for version 6.2.0 and below. Since I upgraded to latest version, cli can't work with .ts anymore and it is throwing error

ts-node node_modules/.bin/sequelize db:migrate

.sequelizerc content

const path = require('path');
module.exports = {
   'migrations-path': path.resolve('./migrations'),
   'config': path.resolve('./src/config', 'database.ts')
}

What is actually happening?


Sequelize CLI [Node: 17.5.0, CLI: 6.4.1, ORM: 6.18.0]


ERROR: Error reading "src/config/database.ts". Error: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/nguyentrungluu/Documents/self-learn/nestjs/src/config/database.ts

__Dialect: postgres __Sequelize CLI version:6.4.1

luunguyenbk avatar Apr 08 '22 10:04 luunguyenbk

I believe that's because we load files using import()

You'll need to use ts-node's esm loader on this

ephys avatar Apr 15 '22 21:04 ephys

Is there any update?

tesar27 avatar Jun 29 '22 01:06 tesar27

Our recommendation is currently still to either:

  • transpile your migrations before executing them with sequelize-cli (highly recommended)
  • run the cli using ts-node-esm

We're open to PRs and propositions to improve the solution

ephys avatar Jul 09 '22 19:07 ephys

Can you use npx sequelize-cli db:migrate --url 'mysql://root:password@mysql_host.com/database_name'

I-am-Nikola avatar Jul 22 '23 12:07 I-am-Nikola

The issue seems to have started in sequelize-cli v6.4.0

ledenis avatar Aug 23 '23 20:08 ledenis