SailsJs - 解除问题(orm hook无法加载)

时间:2016-04-20 16:36:53

标签: orm sails.js hook

我在Windows下运行我的应用时出现问题。通常情况下,我在Macbook上开发,但我不得不切换。问题是,应用程序已经在没有问题的情况下在Windows上工作。这是一条错误消息:

  

错误:挂钩(orm)无法加载!       详细说明:降帆......       详细:向子进程发送kill信号(8684)...       详细说明:关闭HTTP服务器...       详细信息:HTTP服务器已成功关闭。       错误:TypeError:无法读取undefined的属性'config'           在validateModelDef(C:\ projects \ elearning-builder \ node_modules \ sails \ node_modules \ sails-hook-orm \ lib       \验证模型-def.js:109:84)           在C:\ projects \ elearning-builder \ node_modules \ sails \ node_modules \ sails-hook-orm \ lib \ initialize.js:218       :36           在arrayEach(C:\ projects \ elearning-builder \ node_modules \ sails \ node_modules \ lodash \ index.js:1289:13)           在功能。 (C:\项目\网络学习助洗剂\ node_modules \帆\ node_modules \ lodash \ index.j       S:3345:13)           at Array.async.auto._normalizeModelDefs(C:\ projects \ elearning-builder \ node_modules \ sails \ node_module       小号\帆形钩-ORM \ lib中\ initialize.js:216:11)           at listener(C:\ projects \ elearning-builder \ node_modules \ sails \ node_modules \ sails-hook-orm \ node_module       小号\异步\ lib中\ async.js:605:42)           在C:\ projects \ elearning-builder \ node_modules \ sails \ node_modules \ sails-hook-orm \ node_modules \ async \ li       b \ async.js:544:17           at _arrayEach(C:\ projects \ elearning-builder \ node_modules \ sails \ node_modules \ sails-hook-orm \ node_modu       LES \异步\ lib中\ async.js:85:13)           在Immediate.taskComplete(C:\ projects \ elearning-builder \ node_modules \ sails \ node_modules \ sails-hook-o       RM \ node_modules \异步\ lib中\ async.js:543:13)           at processImmediate [as _immediateCallback](timers.js:383:17)       PS C:\ projects \ elearning-builder>

我试着检查一下,\node_modules\sails\node_modules\sails-hook-orm\lib\validate-model-def.js:109:84到底发生了什么     所以我暂时添加了简单的console.log:

  console.log("error in line below", hook);
  var normalizedDatastoreConfig = hook.datastores[normalizedModelDef.connection[0]].config;

结果我看到了:

error in line below Hook {
  load: [Function: wrapper],
  defaults:
   { globals: { adapters: true, models: true },
     orm: { skipProductionWarnings: false, moduleDefinitions: [Object] },
     models: { connection: 'localDiskDb' },
     connections: { localDiskDb: [Object] } },
  configure: [Function: wrapper],
  loadModules: [Function: wrapper],
  initialize: [Function: wrapper],
  config: { envs: [] },
  middleware: {},
  routes: { before: {}, after: {} },
  reload: [Function: wrapper],
  teardown: [Function: wrapper],
  identity: 'orm',
  configKey: 'orm',
  models:
   { /* models here, I removed this as it was too long /*},
  adapters: {},
  datastores: {} }

因此,normalizedModelDef.connection[0]的值为development。但是hook.datastores是空的?这就是为什么没有config属性。

但问题是,我在config / connections.js中有连接

喜欢这里:

development: {
        module    : 'sails-mysql',
        host      : 'localhost',
        port      : 3306,
        user      : 'ebuilder',
        password  : 'ebuilder',
        database  : 'ebuilder'
    },
    production: {
        /* details hidden ;) */
    },
    testing: {
        /* details hidden ;) */
    }

任何建议/提示都非常感谢。

3 个答案:

答案 0 :(得分:1)

您定义了一些连接,但是您是否定义了可能在config / models.js中指定的默认连接?例如,如果你有:

    module.exports.models = {
      connection: 'mysql',
      ...

然后需要在你的connections.js

中定义'mysql'

答案 1 :(得分:1)

正如我在你的config / connections.js中看到的那样

development: {
        module    : 'sails-mysql',
        host      : 'localhost',
        port      : 3306,
        user      : 'ebuilder',
        password  : 'ebuilder',
        database  : 'ebuilder'
    },

您提供的module : 'sails-mysql不正确。它应该是adapter:'sails-mysql'

development: {
        adapter   : 'sails-mysql',
        host      : 'localhost',
        port      : 3306,
        user      : 'ebuilder',
        password  : 'ebuilder',
        database  : 'ebuilder'
    },

答案 2 :(得分:0)

检查您的控制器或型号是否包含任何错误代码。像任何符号。当我的控制器在api开始之前或之后包含任何字符时,我遇到了同样的问题