Sequelize + Typescript build error. pg-native and not a constructor.
See original GitHub issueWhat 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:
- Created 7 years ago
- Comments:9 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@lrojas94 Sequelize 3 uses
module.exports =
, so you have to doimport Sequlize = require('sequelize')
instead ofimport 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 😃
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.