[英]NodeJs can not find function
我有一個NodeJs項目,並且某些導入的庫無法正常工作,即書架和pg。 這個問題似乎不是來自庫,因為它們是可通過npm獲得的“官方”軟件包。
這是一個無法正常運行的代碼段:
var pg = require('pg');
pg.connect('postgres://postgres:password@localhost:5432/myproject');
給我以下錯誤:
pg.connect();
TypeError: pg.connect is not a function
盡管函數connect()顯然存在,並且應該根據文檔以這種方式進行訪問。
書架也會發生這種情況。 如果我嘗試這樣的事情:
var knex = require('knex')({
client: 'mysql',
connection: {
host : 'localhost',
user : 'root',
password : 'mypw',
database : 'userdb',
charset : 'utf8'
}
});
var bookshelf = require('bookshelf')(knex);
var User = bookshelf.Model.extend({
tableName: 'user'
})
bookshelf.plugin('registry');
module.exports = bookshelf;
IDE告訴我,如果我將光標懸停在Model
上,並且嘗試使用以下命令在數據庫中創建新條目,則找不到Model
new User({username: 'test',
.... })
我說一個錯誤
TypeError: User is not a constructor
同樣,我使用了圖書館書架的官方文檔來創建最后一個片段。
我也使用express,hogan,bcrypt,它們工作得很好。
這可能是什么問題?
關於connect
功能的問題:
var pg = require('pg');
var conString = "postgres://postgres:password@localhost:5432/myproject";
var client = new pg.Client(conString);
client.connect();
connect
函數在Client
聲明
通過此鏈接獲取有關node-postgres
軟件包https://github.com/brianc/node-postgres的更多文檔
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.