Comments (9)
DataModel extends from Model. Can you post the full stack trace?
from loopback-boot.
Sure
assert.js:92
throw new assert.AssertionError({
^
AssertionError: Model must be a descendant of loopback.Model
at Function.app.model (/Users/oleksiistrutsynskyi/Documents/api/node_modules/loopback/lib/application.js:144:5)
at ip (/Users/oleksiistrutsynskyi/Documents/api/app.js:48:9)
at Array.forEach (native)
at Object.<anonymous> (/Users/oleksiistrutsynskyi/Documents/api/app.js:46:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
from loopback-boot.
I just enhanced the error message with strongloop/loopback@a28e5b5. Can you tell which model is offending?
If you can show me the complete code for your model, it will be helpful.
from loopback-boot.
Now it says:
AssertionError: undefined must be a descendant of loopback.Model
Thanks - will do investigation why it is undefined :(
from loopback-boot.
I don't sure how to solve the issue... I have 2 files:
userIdentity.json
{
"name": "userIdentity",
"options": {
"base": "UserIdentity",
"relations": {
"user": {
"model": "user",
"type": "belongsTo",
"foreignKey": "userId"
}
}
},
"public": true
}
userIdentity.js
var loopback = require('loopback');
module.exports = function(userIdentity, UserIdentity) {
userIdentity.prototype.test = function(duration, cb) {
cb('test');
};
};
loopback.remoteMethod(userIdentity.test, {
returns: {
arg: 'test',
type: 'object',
},
accepts: [
{arg: 'test', type: 'Object', required: true, description: 'test', http: {source: 'body'}}
],
http: {verb: 'POST', path: '/test'}
});
and in my app.js
// Create an instance of PassportConfigurator with the app instance
var PassportConfigurator = require('loopback-component-passport').PassportConfigurator;
var passportConfigurator = new PassportConfigurator(app);
// Initialize passport
passportConfigurator.init();
boot(app, __dirname);
// Set up related models
passportConfigurator.setupModels({
userModel: app.models.user,
userIdentityModel: app.models.userIdentity,
userCredentialModel: app.models.userCredential
});
// Configure passport strategies for third party auth providers
for(var s in config) {
var c = config[s];
c.session = c.session !== false;
passportConfigurator.configureProvider(s, c);
}
And the issue: Until I decided to add/extend userIdentity.js - everything was fine. But I after I try to extend userIdentity..... to be honest I can't do it :(
I am getting following error
/Users/oleksiistrutsynskyi/Documents/api/models/userIdentity.js:9
loopback.remoteMethod(userIdentity.test, {
^
ReferenceError: userIdentity is not defined
at Object.<anonymous> (/Users/oleksiistrutsynskyi/Documents/api/models/userIdentity.js:9:23)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at /Users/oleksiistrutsynskyi/Documents/api/node_modules/loopback-boot/lib/executor.js:156:20
at Array.forEach (native)
at defineModels (/Users/oleksiistrutsynskyi/Documents/api/node_modules/loopback-boot/lib/executor.js:141:23)
from loopback-boot.
In userIdentity.js, you should do something like:
var loopback = require('loopback');
var app = require('../app');
var userIdentity = app.models.userIdentity;
userIdentity.prototype.test = function(duration, cb) {
cb('test');
};
loopback.remoteMethod(userIdentity.test, {
returns: {
arg: 'test',
type: 'object',
},
accepts: [
{arg: 'test', type: 'Object', required: true, description: 'test', http: {source: 'body'}}
],
http: {verb: 'POST', path: '/test'}
});
from loopback-boot.
Tried it and getting:
/Users/oleksiistrutsynskyi/Documents/api/models/userIdentity.js:4
userIdentity.prototype.test = function(duration, cb) {
^
TypeError: Cannot read property 'prototype' of undefined
at Object.<anonymous> (/Users/oleksiistrutsynskyi/Documents/api/models/userIdentity.js:4:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at /Users/oleksiistrutsynskyi/Documents/api/node_modules/loopback-boot/lib/executor.js:156:20
at Array.forEach (native)
at defineModels (/Users/oleksiistrutsynskyi/Documents/api/node_modules/loopback-boot/lib/executor.js:141:23)
from loopback-boot.
Seems like at this step the model is not in app.models yet
from loopback-boot.
After debugging figured correct way to implement it:
var loopback = require('loopback');
module.exports = function(userIdentity) {
userIdentity.test = function(duration, callback) {
callback(null, 'test done');
};
loopback.remoteMethod(userIdentity.test, {
returns: {
arg: 'test',
type: 'object',
},
accepts: [
{arg: 'test', type: 'Object', required: true, description: 'test', http: {source: 'body'}}
],
http: {verb: 'POST', path: '/test'}
});
};
from loopback-boot.
Related Issues (20)
- Subfolders in boot folder HOT 7
- [forward-port] Fix resolution of middleware modules
- Boot scripts are loaded, but not actually run HOT 9
- organizing configuration files leads to problems HOT 3
- test failing on browserify due to form-data HOT 1
- Document refactored design of loopback-boot HOT 1
- datasources duplicated when booting using a config HOT 1
- models not loaded when using config on boot HOT 1
- 3.0.0
- Async boot scripts - silent failure with security risk HOT 6
- resolveAppScriptPath() is not pass scriptExtensions to fixFileExtensions() HOT 2
- [BUG] Middleware is loading .js.map of .js HOT 1
- The middleware "loopback#static" in phase "files"is not defined in the main config
- Async operations in component initialization HOT 3
- isomorphic and uglify causing "AssertionError: must provide a valid {{SharedClass}}" HOT 1
- custom middleware not found when boot options are just __dirname HOT 2
- Why next() requires to trigger process.nextTick in bootscript. HOT 2
- export-api-def doesn't work with loopback-boot@3 HOT 1
- Address usage of config/application on boot LBOptions HOT 2
- Loopback-boot updating to 3.3.1 producting "LoopBack server listening @ https://undefined:undefined/" HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from loopback-boot.