10

Running Sequelize -m

in my config.json

"development": {
    "username": "root",
    "password": null,
    "database": "**********",
    "dialect": "postgres",
    "protocol": "postgres",
    "port": 5432,
    "host": "127.0.0.1"
},

getting error:

sequelize -m
Loaded configuration file "config/config.json".
Using environment "development".

/usr/local/lib/node_modules/sequelize/lib/transaction-manager.js:10
    throw new Error("The dialect " + sequelize.getDialect() + " is not support
          ^
Error: The dialect postgres is not supported.
    at new module.exports (/usr/local/lib/node_modules/sequelize/lib/transaction-manager.js:10:11)
    at new module.exports.Sequelize (/usr/local/lib/node_modules/sequelize/lib/sequelize.js:128:31)
    at Object.<anonymous> (/usr/local/lib/node_modules/sequelize/bin/sequelize:225:27)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

Is there a problem in my config, or something else that could be the issue?

8 Answers 8

14

I've stumbled upon the same problem. You should install pg module globally. Here's the command:

npm install -g pg
Sign up to request clarification or add additional context in comments.

Comments

7

Nope!

You need to install pg-hstore.

See here: https://github.com/sequelize/sequelize/issues/2949

Comments

6

You need to have

$ npm install pg --save
$ npm install pg-hstore --save
$ npm install sequelize --save

Also create the database separately, sequelize doesn't create the db for you.

var Sequelize = require("sequelize");

// make sure you have created the database using pg Admin III 
var sequelize = new Sequelize("postgres://postgres:postgres@localhost:5432/yourdbname");

var Person = sequelize.define('person', {
  firstName: {
    type: Sequelize.STRING
  },
  lastName: {
    type: Sequelize.STRING
  }
});

Person.sync({force: true}).then(function () {
  return Person.create({
    firstName: 'jj',
    lastName: 'Hancock'
  });
});

Comments

4

I've run npm install --save pg inside sequelize directory and everything is fine now.

Comments

2

Did an strace on the application. It seems Sequelize v2.x was searching for 'pg-native.

npm install -g pg-native

Comments

2

I have run root@# "npm install pg pg-hstore sequelize --save" and it resolve the issue for me. Thanks !

Comments

1

The doc says:

With the release of Sequelizev1.6.0, the library got independent from specific dialects. That mean, that you'll have to add the respective dialect library yourself. Another option is the use of the sequelize packages that ship the dialect libraries as well.

Then you might have missed to require the library, see Sequelize docs.

1 Comment

I have the pg module installed and running with sequelize in the application. The only place it doesn't work is when running the binary for migrations. at this point is where I get the 'error'. The dialect is working throughout the rest of the application
0

A more detailed thread of this issue can be found in the sequelize issue

Installing pg-native npm i pg-native solved for my case (also suggested above by Hakkar).

  • I was having the same issue while using npm so the problem is not linked to yarn (as suggested above)
  • I can't install it globally, as suggested, because I need it to run in a Lambda function
  • I installed npm i --save pg and also installed npm i -D @types/pg because I'm using TS
  • I imported import * as pg from 'pg'; and also import { Sequelize } from 'sequelize';, then const s = new Sequelize(connecStr, {dialectModule: pg})
  • I do not need to manually configure webpack and do not want to include it just for the sake of making a SQL query
  • Also tried to reboot node_modules and package-lock.json

After installing pg-native it solved my case.

Hope that helps

Related issues:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.