Error: Dialect needs to be explicitly supplied as of v4.0.0

Open
#1,510 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript
Domain
cli, databases

Research direction

Start with .sequelizerc, then compare the loading and environment selection for config.json and config.sequelize.js. Run npx sequelize-cli db:migrate with the supplied configuration and inspect how the development entry is read. Done means the JavaScript configuration loads the dialect and the migration completes without the dialect error.

Written by the indexing model from the issue text.

Description

1. Issue Description
'Error: Dialect needs to be explicitly supplied as of v4.0.0' is thrown when initialising sequelize via a destructured property whilst running 'npx sequelize-cli db:migrate'.

2. What are you doing?
I have a 2 file config:

  • config.sequelize.js
  • config.json
    --> I want to use the config.sequelize.js file to use environment variables to secure information.
    I config file .sequelizerc with path config.json --> it's working

$ npx sequelize-cli db:migrate Sequelize CLI [Node: 20.14.0, CLI: 6.6.2, ORM: 6.37.3] Loaded configuration file "src\config\config.json". Using environment "dev". == 20240629071618-create-user: migrating ======= == 20240629071618-create-user: migrated (0.063s)

But, I use file config.sequelize.js , I get an error:

$ npx sequelize-cli db:migrate Database Type: mysql Sequelize CLI [Node: 20.14.0, CLI: 6.6.2, ORM: 6.37.3] Loaded configuration file "src\config\config.sequelize.js". ERROR: Dialect needs to be explicitly supplied as of v4.0.0

3. Additional context

3.1. File config/config.json
{ "dev": { "username": "root", "password": "", "database": "db2_dev", "host": "127.0.0.1", "port": 6611, "dialect": "mysql" }, "test": { "username": "root", "password": "", "database": "db2_test", "host": "127.0.0.1", "port": "3306", "dialect": "mysql" }, "production": { "username": "root", "password": "", "database": "db2_prod", "host": "127.0.0.1", "port": "3306", "dialect": "mysql" } }

3.2. File config.sequelize.js
`
require("dotenv").config();
console.log("Database Type: ", process.env.DB_TYPE);

module.exports = {
development: {
username: process.env.DEV_DB_USERNAME,
password: process.env.DEV_DB_PASSWORD,
database: process.env.DEV_DB_NAME,
host: process.env.DEV_DB_HOST,
port: process.env.DEV_DB_PORT,
dialect: process.env.DB_TYPE,
},
test: {
username: process.env.DEV_DB_USERNAME,
password: process.env.DEV_DB_PASSWORD,
database: process.env.DEV_DB_NAME,
host: process.env.DEV_DB_HOST,
port: process.env.DEV_DB_PORT,
dialect: process.env.DB_TYPE,
},
production: {
username: process.env.DEV_DB_USERNAME,
password: process.env.DEV_DB_PASSWORD,
database: process.env.DEV_DB_NAME,
host: process.env.DEV_DB_HOST,
port: process.env.DEV_DB_PORT,
dialect: process.env.DB_TYPE,
},
};

`

3.3. File .sequelizerc
`
// .sequelizerc
require("babel-register");
require("dotenv").config();
const path = require("path");

// const { development } = require("./src/config/config.sequelize.js");
module.exports = {
env: process.env.NODE_ENV || "dev",
// config: JSON.stringify(development),
config: path.resolve("./src/config/", "config.sequelize.js"),

"models-path": path.resolve("./src/models/", ""),
"seeders-path": path.resolve("./src/seeders/", ""),
"migrations-path": path.resolve("./src/migrations/", ""),

};
`

4. Environment

  • Sequelize version: 6.37.3
  • Node.js version: 20.14.0
  • Operating System: Windows 10 Pro
Dominant language
JavaScript
Stars
2.6k
Forks
524
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sequelize/cli

All issues in sequelize/cli

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.