Skip to content
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

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

Open
quanganh-snake opened this issue Jun 29, 2024 · 2 comments
Open

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

quanganh-snake opened this issue Jun 29, 2024 · 2 comments

Comments

@quanganh-snake
Copy link

quanganh-snake commented Jun 29, 2024

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
@WikiRik
Copy link
Member

WikiRik commented Jun 29, 2024

In config.sequelize.js you have development defined, instead of dev which is the environment that is used. That's why it doesn't know which dialect you want to use

@quanganh-snake
Copy link
Author

Trong config.sequelize.js bạn đã developmentxác định, thay vào devđó là môi trường được sử dụng. Đó là lý do tại sao nó không biết bạn muốn sử dụng phương ngữ nào

Oh shit, Thank you very much, I have fixed it. What a silly mistake 🤣🤣🤣

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants