2

I am having problems with running my app under windows. Normally, I am developing on Macbook but temporarly I had to switch. The thing is, that the app was already working on windows without problems. Here is an error message:

error: A hook (orm) failed to load! verbose: Lowering sails... verbose: Sent kill signal to child process (8684)... verbose: Shutting down HTTP server... verbose: HTTP server shut down successfully. error: TypeError: Cannot read property 'config' of undefined at validateModelDef (C:\projects\elearning-builder\node_modules\sails\node_modules\sails-hook-orm\lib \validate-model-def.js:109:84) at C:\projects\elearning-builder\node_modules\sails\node_modules\sails-hook-orm\lib\initialize.js:218 :36 at arrayEach (C:\projects\elearning-builder\node_modules\sails\node_modules\lodash\index.js:1289:13) at Function. (C:\projects\elearning-builder\node_modules\sails\node_modules\lodash\index.j s:3345:13) at Array.async.auto._normalizeModelDefs (C:\projects\elearning-builder\node_modules\sails\node_module s\sails-hook-orm\lib\initialize.js:216:11) at listener (C:\projects\elearning-builder\node_modules\sails\node_modules\sails-hook-orm\node_module s\async\lib\async.js:605:42) at 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\async\lib\async.js:85:13) at Immediate.taskComplete (C:\projects\elearning-builder\node_modules\sails\node_modules\sails-hook-o rm\node_modules\async\lib\async.js:543:13) at processImmediate [as _immediateCallback] (timers.js:383:17) PS C:\projects\elearning-builder>

I tried to check it out, what exactly is happening in \node_modules\sails\node_modules\sails-hook-orm\lib\validate-model-def.js:109:84 so I added simple console.log temporarly:

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

And as a result I see:

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: {} }

So, the normalizedModelDef.connection[0] has value development. But hook.datastores is empty? That is why there is no config property.

But the thing is, I do have connections in my config/connections.js

Like here:

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

Any suggestions/tips highly appreciated.

Alexandre Neukirchen
  • 2,713
  • 7
  • 26
  • 36
DeJoT
  • 73
  • 2
  • 6

3 Answers3

1

You have some connections defined, but do you have the default connection defined that might be specified in config/models.js? If for example you have:

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

then 'mysql' needs to be defined in your connections.js

Rob Kraft
  • 216
  • 3
  • 6
1

As I see in your config/connections.js

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

You have given module : 'sails-mysql which is not correct. It should be adapter:'sails-mysql'

development: {
        adapter   : 'sails-mysql',
        host      : 'localhost',
        port      : 3306,
        user      : 'ebuilder',
        password  : 'ebuilder',
        database  : 'ebuilder'
    },
ddb
  • 2,423
  • 7
  • 28
  • 38
0

check your controller or models contains any error code. like any symbol. i had face same problem while my controller contain any character before or after api started

Arjun Kava
  • 5,303
  • 3
  • 20
  • 20