question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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’.

What are you doing?

I have a config.js which merges different sections of a config.json dependent on the environment so as to prevent repeated configurations, it exports the final, merged, configuration. Within the final configuration is a sub object of ‘dev’ called ‘database’.

Sequelize’s .sequelizerc is unable to process this as the config paramter expects a file path, not an object and thus is not using the ‘database’ object and instead is using the whole object. When trying to run ‘npx sequelize-cli db:migrate’ the error above is thrown.

If I change config.js to instead export ‘finalConfig.database’, ‘npx sequelize-cli db:migrate’ works without issue.

What do you expect to happen?

For ‘npx sequelize-cli db:migrate’ to migrate successfully.

What is actually happening?

An error is thrown.

Sequelize CLI [Node: 15.5.1, CLI: 6.2.0, ORM: 6.3.5]

Loaded configuration file "config\config.js".

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

Additional context

config/config.json

{
  "dev": {
    "database": {
      "name": "name",
      "host": "host",
      "username": "user",
      "password": "pass",
      "dialect": "postgres"
    }
  },
  "live": {
    "database": {
      "name": "name1",
      "username": "username1",
      "password": "password1"
    }
  }
}

Works config/config.js

const _ = require('lodash');
const config = require('./config.json');
const defaultConfig = config.dev;
const environment = process.env.NODE_ENV || 'dev';
const environmentConfig = config[environment];
const finalConfig = _.merge(defaultConfig, environmentConfig);

module.exports = finalConfig.database;

Does not work config/config.js

module.exports = finalConfig;

Environment

  • Sequelize version: 6.3.5
  • Node.js version: 15.5.1
  • Operating System: Windows 10

Issue Template Checklist

How does this problem relate to dialects?

  • I think this problem happens regardless of the dialect.
  • I think this problem happens only for the following dialect(s):
  • I don’t know, I was using postgres, with connector library version 8.5.1 and database version 11.6 (ElephantSQL)

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • No, I don’t have the time, although I believe I could do it if I had the time…
  • Yes, I have the time but I don’t know how to start, I would need guidance.
  • No, I don’t have the time and I wouldn’t even know how to start.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
Asharudheen-VNCcommented, Jun 21, 2021

Use this export NODE_ENV=development

2reactions
moigamijuniorcommented, Nov 1, 2021

Some news? I have the same issue when running with pm2. Running with npm start ou nodemon works fine. Some clue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Dialect needs to be explicitly supplied as of v4.0.0
Solution for me was based on what I had set for my NODE_ENV variable. echo $NODE_ENV. If you do not have anything set...
Read more >
Error: Dialect needs to be explicitly supplied as of v4.0.0 ...
'Error: Dialect needs to be explicitly supplied as of v4.0.0' is thrown when initialising sequelize via a destructured property whilst running ' ...
Read more >
Dialect needs to be explicitly supplied as of v4.0.0, forest ...
Hello, I found a similar problem on stackoverflow. It seems to be a problem of dialect or configuration of sequelize. Tell me if...
Read more >
Dialect needs to be explicitly supplied as of v4.0.0-sequelize.js
Solution for me was based on what I had set for my NODE_ENV variable. echo $NODE_ENV. If you do not have anything set...
Read more >
Node.js – Dialect needs to be explicitly supplied as of v4.0.0
Node.js – Dialect needs to be explicitly supplied as of v4.0.0 ... I have been working on a NodeJS project which uses PostgreSQL...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found