strongloop/loopback-component-push

Installation and Notification models are not found

Closed this issue · 3 comments

I used npm to install loopback-component-push but when I try to use Installation as a base model I get the following.

/home/user/app/node_modules/loopback/lib/registry.js:273
  throw new Error('Model not found: ' + modelName);
        ^
Error: Model not found: Installation
    at Function.registry.getModel (/home/user/app/node_modules/loopback/lib/registry.js:273:9)
    at Function.registry.createModel (/home/user/app/node_modules/loopback/lib/registry.js:103:22)
    at /home/user/app/node_modules/loopback-boot/lib/executor.js:187:28
    at Array.forEach (native)
    at defineModels (/home/user/app/node_modules/loopback-boot/lib/executor.js:171:23)
    at setupModels (/home/user/app/node_modules/loopback-boot/lib/executor.js:160:3)
    at execute (/home/user/app/node_modules/loopback-boot/lib/executor.js:33:3)
    at bootLoopBackApp (/home/user/app/node_modules/loopback-boot/index.js:129:3)
    at Object.<anonymous> (/home/user/app/server/server.js:10:1)
    at Module._compile (module.js:456:26)

I checked and double checked everything in the example/server-2.0 to make sure I was doing everything the same so I am not sure why the model is not showing up. I tried the example as a sanity check and it has no problem finding the models.

server/models/installation.json

{
   "name": "installation",
   "base": "Installation"
}

server/model-config.json

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ]   
  },

...

  "installation": {
    "dataSource": "db",
    "public": true
  },
  "app": {
    "dataSource": "db",
    "public": true
  }
}

server/server.js

var loopback = require('loopback');
var boot = require('loopback-boot');
//var path = require('path');
var app = module.exports = loopback();


//app.use(loopback.static(path.resolve(__dirname, '../client/www/')));
// Bootstrap the application, configure models, datasources and middleware.
// Sub-apps like REST API are mounted via boot scripts.
boot(app, __dirname);

...

package.json

{
  "name": "app",
  "version": "1.0.0",
  "main": "server/server.js",
  "scripts": {
    "pretest": "jshint .",
    "test": "mocha"
  },  
  "dependencies": {
    "async": "^0.9.0",
    "bower": "^1.3.12",
    "compression": "^1.0.3",
    "errorhandler": "^1.1.1",
    "loopback": "^2.8.0",
    "loopback-boot": "^2.4.0",
    "loopback-component-push": "~1.3.0",
    "loopback-component-storage": "^1.3.0",
    "loopback-connector-mongodb": "^1.6.0",
    "loopback-datasource-juggler": "^2.7.0",
    "serve-favicon": "^2.0.1"
  },  
  "optionalDependencies": {
    "loopback-explorer": "^1.1.0"
  },  
  "devDependencies": {
    "jshint": "^2.5.6",
    "mocha": "^2.1.0",
    "supertest": "^0.15.0"
  },  
  "repository": {
    "type": "", 
    "url": ""
  },  
  "description": "Testing push"
}

Hey @raymondfeng thanks for getting back to me.

I was using that example as my starting ground. The server-2.0 example works but when I try to do it in a fresh project I get the error again. I have tried practically everything so I am really lost as to why it is not working.

The issue should come up if you start a fresh project, install loopback-component-push then create any model that tries to use "Installation" as the base model.

I tried checking to see if index.js was being called inside of the loopback-component-push when I started the app and it is being called and all of the models seem to be exporting from it properly so I guess at some point a long the way they are getting dropped. I checked inside of loopback/lib/registry.js and when getModel is called the Installation model is not present in ModelBuilder.models.

I have also tried to mess with package.json a bit to see if it was a versioning issue but it seems like it is not.

Hope this helps a bit.

I found the problem.

It turns out if you do not have the "push" datasource setup in datasource.json then this error will pop up. I just copied your datasource definition and it worked as expected.