尝试使用Postgres数据库配置Sequelize。我正在使用Webpack捆绑我的应用程序。当我整合Sequelize时:
var Sequelize = require('sequelize');
我的终端出现以下错误:
WARNING in ./~/sequelize/lib/sequelize.js
Critical dependencies:
654:60-73 the request of a dependency is an expression
@ ./~/sequelize/lib/sequelize.js 654:60-73
WARNING in ./~/sequelize/lib/dialects/mssql/connection-manager.js
Critical dependencies:
17:15-71 the request of a dependency is an expression
@ ./~/sequelize/lib/dialects/mssql/connection-manager.js 17:15-71
WARNING in ./~/sequelize/lib/dialects/mysql/connection-manager.js
Critical dependencies:
18:17-60 the request of a dependency is an expression
@ ./~/sequelize/lib/dialects/mysql/connection-manager.js 18:17-60
WARNING in ./~/sequelize/lib/dialects/postgres/connection-manager.js
Critical dependencies:
18:41-92 the request of a dependency is an expression
18:102-153 the request of a dependency is an expression
@ ./~/sequelize/lib/dialects/postgres/connection-manager.js 18:41-92 18:102-153
WARNING in ./~/sequelize/lib/dialects/sqlite/connection-manager.js
Critical dependencies:
22:15-71 the request of a dependency is an expression
@ ./~/sequelize/lib/dialects/sqlite/connection-manager.js 22:15-71
WARNING in ./~/sequelize/lib/dialects/mysql/connection-manager.js
Module not found: Error: Cannot resolve module 'mysql' in /Users/dace/Code/personal/airthere/node_modules/sequelize/lib/dialects/mysql
@ ./~/sequelize/lib/dialects/mysql/connection-manager.js 20:17-33
ERROR in ./~/sequelize/package.json
Module parse failed: /Users/dace/Code/personal/airthere/node_modules/sequelize/package.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
| "_args": [
| [
| "sequelize@^3.19.1",
@ ./~/sequelize/lib/sequelize.js 245:20-46
ERROR in ./~/moment-timezone/data/packed/latest.json
Module parse failed: /Users/dace/Code/personal/airthere/node_modules/moment-timezone/data/packed/latest.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
| "version": "2015g",
| "zones": [
| "Africa/Abidjan|LMT GMT|g.8 0|01|-2ldXH.Q|48e5",
@ ./~/moment-timezone/index.js 2:15-51
我认为这是一个与webpack相关的问题,因为我可以让Sequelize在不使用webpack的项目中运行。我只是不确定它是什么。看起来最后两个可能与需要webpack的加载器有关(不确定哪些),而其他警告是依赖关系的,或者依赖是表达式(不确定这意味着什么)。
非常感谢任何和所有帮助。感谢。
答案 0 :(得分:0)
更新:有人向我指出,这是在客户端完成的,这是错误的方法。我将这个Sequelize数据库配置移动到我的server.js文件中(它保存了我的快速配置),当webpack不再与它接口时,它运行良好:
const express = require('express');
const app = express();
var Sequelize = require('sequelize');
var connection = new Sequelize('dev', 'dace', 'root', {
dialect: 'postgres',
});
const PORT = (process.env.PORT || 3000);
app.get('/', function(req, res) {
var Article = connection.define('article', {
name: Sequelize.STRING,
})
connection.sync().then(function() {
Article.create({
name: 'Dace'
});
});
})
app.listen(PORT, function() {
console.log(`Listening on port ${PORT}...`);
});
不是最终应该如何配置,而是足以得到我正在尝试做的工作示例。