无法读取未定义的属性“同步" [英] Cannot read property 'sync' of undefined

查看:58
本文介绍了无法读取未定义的属性“同步"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何使用 hapi 服务器和其他一些包在 Nodejs 中设置基本 mvc 的教程.

I am following a tutorial on how to set up a basic mvc in Nodejs using the hapi server and a few other packages.

教程:https://www.sitepoint.com/node-js-mvc-application/

我的项目的 Git:https://github.com/christoph88/node-js-mvc-tut/

当我尝试启动服务器时出现错误:

I have an error when I try to launch the server:

~/Projects/node-js-mvc-tut$ node server.js 
/home/christoph/Projects/node-js-mvc-tut/server.js:33
Models.sequelize.sync().then(() => {
^
TypeError: Cannot read property 'sync' of undefined
at Object.<anonymous> (/home/christoph/Projects/node-js-mvc-tut/server.js:33:17)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3

模型是在需求中定义的.我不明白为什么同步未定义.在 lib/index.js 文件中需要 Sequelise.

Model is defined within the requirements. I do not understand why sync is undefined. Sequelise is required within the lib/index.js file.

'use strict';

const Hapi = require('hapi');
const Hoek = require('hoek');
const Path = require('path');
const Settings = require('./settings');
const Routes = require('./lib/routes');
const Models = require('./lib/models/');

const server = new Hapi.Server();

server.connection({ port: Settings.port });

server.register([
    require('vision'),
    require('inert')
], (err) => {
  Hoek.assert(!err, err);

  server.views({
    engines: { pug: require('pug') },
    path: Path.join(__dirname, 'lib/views'),
    compileOptions: {
      pretty: false
    },
    isCached: Settings.env === 'production'
  });

  // Add routes
  server.route(Routes);
});

Models.sequelize.sync().then(() => {
  server.start((err) => {
    Hoek.assert(!err, err);
    console.log(`Server running at: ${server.info.uri}`);
  });
});

有人可以帮我解决这个问题吗?让它运行会很棒,这样我就可以尝试使其适应我的需求.

Can somebody help me with this? Would be great to get this running so I can try to adapt it to my needs.

推荐答案

我通过将我的 index.js 文件移动到模型文件夹来让它工作.

I have got it working by moving my index.js file to the models folder.

此文件包含在模型中分派续集从而解决问题的必要脚本.

This file has the necessairy scripts that dispatches sequelise in the model thus fixing the problem.

这篇关于无法读取未定义的属性“同步"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆