Sequelize CLI TypeScript
raw JSON → 3.2.0-c verified Sat Apr 25 auth: no javascript
A TypeScript-aware CLI for Sequelize that generates TypeScript migration, model, and seed files instead of JavaScript. Version 3.2.0-c is an early release with experimental Sequelize v4 support. Unlike the standard sequelize-cli, this package introduces separate source and compiled paths for migrations (migrations-source-path and migrations-compiled-path) to accommodate TypeScript compilation. Developers must compile migrations before running db:migrate. The CLI provides commands for database creation, migration management, seeding, and model generation. Maintained by the community, it targets Node >=4.
Common errors
error Error: Cannot find module '../node_modules/sequelize-cli-typescript/lib/commands' ↓
cause Missing or incorrect installation; global vs local mismatch.
fix
Reinstall locally: npm install --save sequelize-cli-typescript. Use npx sequelize to run.
error No migrations to run. ↓
cause Migrations are TypeScript files, not compiled to JS in the expected compiled path.
fix
Compile migrations using TypeScript compiler (tsc) and ensure output goes to migrations-compiled-path.
error dialect dependency not found ↓
cause Missing database driver for the configured dialect.
fix
Install the appropriate dialect package: npm install --save pg pg-hstore (for PostgreSQL), mysql2 (for MySQL), sqlite3 (for SQLite), or tedious (for MSSQL).
Warnings
breaking Migration files are generated as TypeScript, not JavaScript. You MUST compile them before running db:migrate. ↓
fix Add a compile step (e.g., tsc) to your workflow, and ensure the compiled output goes to migrations-compiled-path.
gotcha The CLI uses two separate paths: migrations-source-path (source .ts) and migrations-compiled-path (compiled .js). If not configured, defaults may conflict with standard sequelize-cli expectations. ↓
fix Set both paths in .sequelizerc to avoid confusion. Example: migrations-source-path: './migrations', migrations-compiled-path: './migrations-compiled'.
deprecated Sequelize v4 support is still experimental in this version (3.2.0-c). ↓
fix Use with Sequelize v3 for full support, or test thoroughly with v4.
gotcha The package is named 'sequelize-cli-typescript' on npm, but the CLI binary is still called 'sequelize'. This can cause confusion if both sequelize-cli and sequelize-cli-typescript are installed globally. ↓
fix Uninstall sequelize-cli if you intend to use sequelize-cli-typescript, or use npx to avoid global conflicts.
Install
npm install sequelize-cli-typescript yarn add sequelize-cli-typescript pnpm add sequelize-cli-typescript Imports
- sequelize-cli-typescript wrong
npm install -g sequelize-clicorrectnpm install -g sequelize-cli-typescript - db:migrate wrong
npx sequelize db:migrate --compiledcorrectnpx sequelize db:migrate - model:generate wrong
node_modules/.bin/sequelize model:generate --name User --attributes name:string,email:stringcorrectnpx sequelize model:generate --name User --attributes name:string,email:string
Quickstart
npm install --save sequelize-cli-typescript
npx sequelize init
# Edit .sequelizerc to set migrations-source-path and migrations-compiled-path
npx sequelize model:generate --name User --attributes name:string,email:string
# Compile TypeScript migrations (e.g., tsc)
# Then run migrations
npx sequelize db:migrate