Error: Dialect needs to be explicitly supplied as of v4.0.0
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
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sequelize/cli
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
Similar issues
-
bot:ai-assisted component:compact-js status:untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
midnightntwrk/midnight-sdk#403 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
Difficulty 1/5 1-3 hours Newbie friendliness 86/100
DavidAnson/markdownlint-cli2#940 ·
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
githubnext/gh-aw-workshop#3692 ·
-
agent/guide documentation hive/hosted-available-lke648397-260827-5n31
Difficulty 2/5 1-3 hours Newbie friendliness 90/100