安装lodash后,我最近遇到了一个奇怪的错误。我不知道它是否对我的设置产生了任何影响,但是突然间的sequelize会在方言属性中抛出错误,mysql
不受支持且无法读取property 'dialectName' of undefined
。我不确定为什么会这样,因为我已经使用了sequelize一段时间而且从未出现过。
使用节点v0.10.40
完整错误:
/sequelize/lib/sequelize.js:205
throw new Error('The dialect ' + this.getDialect() + ' is not supported. S
^
Error: The dialect mysql is not supported. Supported dialects: mariadb, mssql, mysql, postgres, and sqlite. (TypeError: Cannot read property 'dialectName' of undefined)
at new Sequelize (/Users/user/Desktop/Projects/node/app-test/node_modules/sequelize/lib/sequelize.js:205:11)
at Object.<anonymous> (/Users/user/Desktop/Projects/node/app-test/app/models/db-index.js:4:17)
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 Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/user/Desktop/Projects/node/app-test/config/passport.js:3:14)
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 Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/user/Desktop/Projects/node/app-test/app/controllers/site-routes.js:4:16)
我的方言设置在哪里:
DB-index.js:
var Sequelize = require('sequelize');
var path = require('path');
var config = require(path.resolve(__dirname, '..', '..','./config/config.js'));
var sequelize = new Sequelize(config.database, config.username, config.password, {
host:'localhost',
port:'3306',
dialect: 'mysql'
});
sequelize.authenticate().then(function(err) {
if (!!err) {
console.log('Unable to connect to the database:', err)
} else {
console.log('Connection has been established successfully.')
}
});
var db = {}
db.Member = sequelize.import(__dirname + "/member");
db.Organization = sequelize.import(__dirname + "/organization");
db.User = sequelize.import(__dirname + "/user");
db.DiscoverySource = sequelize.import(__dirname + "/discovery-source");
db.User.associate(db);
db.Organization.associate(db);
db.DiscoverySource.associate(db);
db.sequelize = sequelize;
db.Sequelize = Sequelize;
sequelize.sync();
module.exports = db;
的package.json:
{
"name": "app-test",
"version": "1.0.0",
"description": "",
"engines": {
"node": "5.0.0"
},
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.14.1",
"cheerio": "^0.20.0",
"connect-flash": "^0.1.1",
"cookie-parser": "^1.4.0",
"express": "^4.13.3",
"express-hbs": "^0.8.4",
"jquery": "^2.2.0",
"lodash": "^4.2.1",
"moment": "^2.10.6",
"morgan": "^1.6.1",
"mysql": "^2.9.0",
"nodemon": "^1.8.1",
"passport": "^0.3.2",
"passport-local": "^1.0.0",
"sequelize": "^3.14.1",
"session": "^0.1.0"
}
}
答案 0 :(得分:3)
你必须安装pakage mysql:
npm install mysql --save
祝你好运^^