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.

Sequelize + Typescript build error. pg-native and not a constructor.

See original GitHub issue

What you are doing?

Basically trying to build a typescript code using sequelize and then compiling it using webpack. However, I seem to be getting two different errors:

  • I’m required to install pg-native (even though native is set to false).
  • If I happen to have pg-native installed, I get:
import Sequelize from 'sequelize';
import {constants} from './../constants.ts';

export var initialized: Boolean = false;

export function initialize():void {
  if(this.initialized){
    return;
  }

  var sequelize = new Sequelize(constants.DATABASE_NAME,constants.DATABASE_USERNAME,constants.DATABASE_PASSWORD,{
    host: constants.DATABASE_HOST,
    dialect: 'postgres',
    native : false,
    pool: {
      maxConnections: 100,
      minConnections: 0,
      maxIdleTime: 10000
    }

  });

  this.initialized = true;
};

I’m just calling the intialize function on my server.js file (which builds and runs just fine if I omit the sequelize functionality)

What do you expect to happen?

I expected it to build and run, as you might expect.

What is actually happening?

I’m getting

ERROR in ./~/pg/lib/native/index.js
Module not found: Error: Cannot resolve module 'pg-native' in /home/luis/Projects/FinalProject-Gamify-Education/node_modules/pg/lib/native
 @ ./~/pg/lib/native/index.js 1:13-33

and, If I manage t install pg-native (which is currently giving away problems to work), I get:

ERROR: new sequelize_1.default is not a constructor. 
which points to the line sequelize = new Sequelize ...

Dialect: postgres Database version: 9.3.13 Sequelize version: 3.23.3

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
felixfbeckercommented, Jun 7, 2016

@lrojas94 Sequelize 3 uses module.exports =, so you have to do import Sequlize = require('sequelize') instead of import Sequelize from 'sequelize'. Sequelize 4 will also support the default export.

@mickhansen you can ping me for TypeScript questions in the future, I’m using Seq + TS in production 😃

0reactions
lrojas94commented, Jun 7, 2016

After reading for a while I see your point now @felixfbecker . Thanks a lot! and you too @mickhansen , I’ll be marking this as solved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ERROR: User is not a constructor -- node js with express ...
After calling save() method in user.service i am getting the error. node.js · express · sequelize.js.
Read more >
internal/modules/cjs/loader.js:969-sequelize.js
Try opening your file again from the original folder. I had the same issue now it's fixed, after changing the location.
Read more >
pg-native - npm
node-pg-native. Build Status. High performance native bindings between node.js and PostgreSQL via libpq with a simple API.
Read more >
Vincit/objection.js - Gitter
hello, is there a quick and easy way to allow a model to only be read only, so if anyone tries to insert,...
Read more >
How to use the pg.types.setTypeParser function in pg - Snyk
Use Snyk Code to scan source code in minutes - no build needed - and fix issues ... console.log("can not load pg-native, using...
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