strongloop / loopback

LoopBack makes it easy to build modern applications that require complex integrations.
http://loopback.io
Other
13.23k stars 1.2k forks source link

Fresh project cannot start using kv-redis connector #2745

Closed penguinpowernz closed 8 years ago

penguinpowernz commented 8 years ago

I just made a fresh project using the following steps:

$ sudo npm install -g strongloop
$ mkdir test
$ cd test
$ slc loopback

I chose 2.x stable for the version and api-server for the application.

Then I did npm install --save loopback-connector-kv-redis and modified my datasources.json file to look like this:

{
  "db": {
    "name": "db",
    "connector": "kv-redis",
    "host": "127.0.0.1",
    "port": 6379
  }
}

Then I did npm start and I get this stacktrace:

> test@1.0.0 start /home/robert/src/test
> node .

/home/robert/src/test/node_modules/loopback-datasource-juggler/lib/datasource.js:495
        modelClass[r.type].call(modelClass, rn, params);
                          ^

TypeError: Cannot read property 'call' of undefined
    at /home/robert/src/test/node_modules/loopback-datasource-juggler/lib/datasource.js:495:27
    at Array.forEach (native)
    at DataSource.defineRelations (/home/robert/src/test/node_modules/loopback-datasource-juggler/lib/datasource.js:456:28)
    at DataSource.setupDataAccess (/home/robert/src/test/node_modules/loopback-datasource-juggler/lib/datasource.js:536:8)
    at DataSource.attach (/home/robert/src/test/node_modules/loopback-datasource-juggler/lib/datasource.js:753:8)
    at Function.ModelClass.attachTo (/home/robert/src/test/node_modules/loopback-datasource-juggler/lib/model-builder.js:339:16)
    at Registry.configureModel (/home/robert/src/test/node_modules/loopback/lib/registry.js:244:15)
    at configureModel (/home/robert/src/test/node_modules/loopback/lib/application.js:466:16)
    at EventEmitter.app.model (/home/robert/src/test/node_modules/loopback/lib/application.js:140:5)
    at /home/robert/src/test/node_modules/loopback-boot/lib/executor.js:202:9
    at Array.forEach (native)
    at setupModels (/home/robert/src/test/node_modules/loopback-boot/lib/executor.js:198:23)
    at execute (/home/robert/src/test/node_modules/loopback-boot/lib/executor.js:39:3)
    at bootLoopBackApp (/home/robert/src/test/node_modules/loopback-boot/index.js:154:3)
    at Object.<anonymous> (/home/robert/src/test/server/server.js:23:1)
    at Module._compile (module.js:409:26)

I didn't even create any models yet.

Here is the package.json file:

{
  "name": "test",
  "version": "1.0.0",
  "main": "server/server.js",
  "scripts": {
    "lint": "eslint .",
    "start": "node .",
    "posttest": "npm run lint && nsp check"
  },
  "dependencies": {
    "compression": "^1.0.3",
    "cors": "^2.5.2",
    "helmet": "^1.3.0",
    "loopback": "^2.22.0",
    "loopback-boot": "^2.6.5",
    "loopback-component-explorer": "^2.4.0",
    "loopback-connector-kv-redis": "^1.0.0",
    "loopback-datasource-juggler": "^2.39.0",
    "serve-favicon": "^2.0.1",
    "strong-error-handler": "^1.0.1"
  },
  "devDependencies": {
    "eslint": "^2.13.1",
    "eslint-config-loopback": "^4.0.0",
    "nsp": "^2.1.0"
  },
  "repository": {
    "type": "",
    "url": ""
  },
  "license": "UNLICENSED",
  "description": "test"
}

The versions I ended up getting were the following:

And here is the initial npm install output:

npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
eslint-config-loopback@4.0.0 node_modules/eslint-config-loopback

serve-favicon@2.3.0 node_modules/serve-favicon
├── parseurl@1.3.1
├── etag@1.7.0
├── fresh@0.3.0
└── ms@0.7.1

cors@2.8.1 node_modules/cors
└── vary@1.1.0

compression@1.6.2 node_modules/compression
├── bytes@2.3.0
├── on-headers@1.0.1
├── vary@1.1.0
├── compressible@2.0.8 (mime-db@1.23.0)
├── debug@2.2.0 (ms@0.7.1)
└── accepts@1.3.3 (negotiator@0.6.1, mime-types@2.1.11)

helmet@1.3.0 node_modules/helmet
├── hpkp@1.1.0
├── dns-prefetch-control@0.1.0
├── ienoopen@1.0.0
├── dont-sniff-mimetype@1.0.0
├── nocache@1.0.0
├── hide-powered-by@1.0.0
├── x-xss-protection@1.0.0
├── frameguard@1.1.0 (lodash.isstring@4.0.1)
├── hsts@1.0.0 (core-util-is@1.0.2)
├── connect@3.4.1 (utils-merge@1.0.0, parseurl@1.3.1, debug@2.2.0, finalhandler@0.4.1)
└── helmet-csp@1.1.0 (lodash.isfunction@3.0.8, platform@1.3.1, camelize@1.0.0, lodash.assign@4.0.4, content-security-policy-builder@1.0.0, lodash.reduce@4.2.0, lodash.some@4.2.0)

nsp@2.6.1 node_modules/nsp
├── path-is-absolute@1.0.0
├── nodesecurity-npm-utils@5.0.0
├── semver@5.1.0
├── cli-table@0.3.1 (colors@1.0.3)
├── chalk@1.1.3 (escape-string-regexp@1.0.5, ansi-styles@2.2.1, supports-color@2.0.0, has-ansi@2.0.0, strip-ansi@3.0.1)
├── wreck@6.3.0 (boom@2.10.1, hoek@2.16.3)
├── rc@1.1.6 (ini@1.3.4, deep-extend@0.4.1, strip-json-comments@1.0.4, minimist@1.2.0)
├── https-proxy-agent@1.0.0 (extend@3.0.0, debug@2.2.0, agent-base@2.0.1)
├── subcommand@2.0.3 (cliclopts@1.1.1, xtend@4.0.1, minimist@1.2.0, debug@2.2.0)
└── joi@6.10.1 (topo@1.1.0, isemail@1.2.0, hoek@2.16.3, moment@2.12.0)

loopback-component-explorer@2.6.0 node_modules/loopback-component-explorer
├── debug@2.2.0 (ms@0.7.1)
├── loopback-swagger@2.7.0 (async@1.5.2, underscore.string@2.3.3, ejs@1.0.0)
├── strong-swagger-ui@21.0.2
├── lodash@3.10.1
└── strong-globalize@2.6.10 (optional@0.1.3, estraverse@4.2.0, word-count@0.2.2, posix-getopt@1.2.0, xtend@4.0.1, async@1.5.2, esprima@2.7.3, md5@2.2.1, mktmpdir@0.1.1, os-locale@1.4.0, mkdirp@0.5.1, htmlparser2@3.9.1, fs-sync@1.0.2, yamljs@0.2.8, g11n-pipeline@1.2.3, lodash@4.15.0)

strong-error-handler@1.1.0 node_modules/strong-error-handler
├── http-status@0.2.3
├── debug@2.2.0 (ms@0.7.1)
├── accepts@1.3.3 (negotiator@0.6.1, mime-types@2.1.11)
├── ejs@2.5.2
└── strong-globalize@2.6.10 (optional@0.1.3, estraverse@4.2.0, word-count@0.2.2, posix-getopt@1.2.0, xtend@4.0.1, async@1.5.2, esprima@2.7.3, md5@2.2.1, mktmpdir@0.1.1, os-locale@1.4.0, mkdirp@0.5.1, htmlparser2@3.9.1, fs-sync@1.0.2, yamljs@0.2.8, g11n-pipeline@1.2.3, lodash@4.15.0)

loopback-boot@2.22.0 node_modules/loopback-boot
├── commondir@0.0.1
├── async@0.9.2
├── toposort@0.2.12
├── semver@4.3.6
├── debug@2.2.0 (ms@0.7.1)
├── lodash@3.10.1
└── strong-globalize@2.6.10 (optional@0.1.3, estraverse@4.2.0, word-count@0.2.2, posix-getopt@1.2.0, xtend@4.0.1, async@1.5.2, esprima@2.7.3, md5@2.2.1, mktmpdir@0.1.1, os-locale@1.4.0, mkdirp@0.5.1, htmlparser2@3.9.1, fs-sync@1.0.2, yamljs@0.2.8, g11n-pipeline@1.2.3, lodash@4.15.0)

loopback@2.34.1 node_modules/loopback
├── uid2@0.0.3
├── stable@0.1.5
├── nodemailer-stub-transport@1.1.0
├── inflection@1.10.0
├── canonical-json@0.0.4
├── depd@1.1.0
├── isemail@1.2.0
├── loopback-connector-remote@1.3.3
├── cookie-parser@1.4.3 (cookie-signature@1.0.6, cookie@0.3.1)
├── debug@2.2.0 (ms@0.7.1)
├── bcryptjs@2.3.0
├── loopback-phase@1.4.0 (async@0.9.2)
├── errorhandler@1.4.3 (escape-html@1.0.3, accepts@1.3.3)
├── body-parser@1.15.2 (content-type@1.0.2, bytes@2.4.0, qs@6.2.0, on-finished@2.3.0, raw-body@2.1.7, http-errors@1.5.0, iconv-lite@0.4.13, type-is@1.6.13)
├── express@4.14.0 (escape-html@1.0.3, array-flatten@1.1.1, cookie-signature@1.0.6, utils-merge@1.0.0, content-type@1.0.2, methods@1.1.2, encodeurl@1.0.1, merge-descriptors@1.0.1, cookie@0.3.1, parseurl@1.3.1, etag@1.7.0, fresh@0.3.0, vary@1.1.0, range-parser@1.2.0, path-to-regexp@0.1.7, serve-static@1.11.1, content-disposition@0.5.1, qs@6.2.0, on-finished@2.3.0, finalhandler@0.5.0, proxy-addr@1.1.2, type-is@1.6.13, accepts@1.3.3, send@0.14.1)
├── ejs@2.5.2
├── nodemailer@2.6.0 (socks@1.1.9, nodemailer-shared@1.1.0, libmime@2.1.0, mailcomposer@3.12.0, nodemailer-direct-transport@3.3.2, nodemailer-smtp-pool@2.8.2, nodemailer-smtp-transport@2.7.2)
├── underscore.string@3.3.4 (util-deprecate@1.0.2, sprintf-js@1.0.3)
├── loopback-context@1.0.0 (continuation-local-storage@3.2.0)
├── strong-globalize@2.6.10 (optional@0.1.3, estraverse@4.2.0, word-count@0.2.2, posix-getopt@1.2.0, xtend@4.0.1, async@1.5.2, esprima@2.7.3, md5@2.2.1, mktmpdir@0.1.1, os-locale@1.4.0, mkdirp@0.5.1, htmlparser2@3.9.1, fs-sync@1.0.2, yamljs@0.2.8, g11n-pipeline@1.2.3, lodash@4.15.0)
├── async@2.0.1 (lodash@4.15.0)
└── strong-remoting@2.31.0 (eventemitter2@2.1.3, qs@6.2.1, js2xmlparser@1.0.0, traverse@0.6.6, sse@0.0.6, mux-demux@3.7.9, request@2.74.0, jayson@1.2.2, xml2js@0.4.17)

loopback-datasource-juggler@2.51.0 node_modules/loopback-datasource-juggler
├── inflection@1.10.0
├── depd@1.1.0
├── async@1.0.0
├── node-uuid@1.4.7
├── qs@3.1.0
├── loopback-connector@2.4.0
├── debug@2.2.0 (ms@0.7.1)
├── traverse@0.6.6
├── minimatch@3.0.3 (brace-expansion@1.1.6)
└── strong-globalize@2.6.10 (optional@0.1.3, estraverse@4.2.0, word-count@0.2.2, posix-getopt@1.2.0, xtend@4.0.1, async@1.5.2, esprima@2.7.3, md5@2.2.1, mktmpdir@0.1.1, os-locale@1.4.0, mkdirp@0.5.1, htmlparser2@3.9.1, fs-sync@1.0.2, yamljs@0.2.8, g11n-pipeline@1.2.3, lodash@4.15.0)

eslint@2.13.1 node_modules/eslint
├── path-is-inside@1.0.2
├── imurmurhash@0.1.4
├── pluralize@1.2.1
├── ignore@3.1.5
├── path-is-absolute@1.0.0
├── globals@9.10.0
├── estraverse@4.2.0
├── strip-json-comments@1.0.4
├── esutils@2.0.2
├── progress@1.1.8
├── text-table@0.2.0
├── user-home@2.0.0 (os-homedir@1.0.1)
├── is-resolvable@1.0.0 (tryit@1.0.2)
├── doctrine@1.4.0 (isarray@1.0.0)
├── debug@2.2.0 (ms@0.7.1)
├── chalk@1.1.3 (escape-string-regexp@1.0.5, supports-color@2.0.0, ansi-styles@2.2.1, strip-ansi@3.0.1, has-ansi@2.0.0)
├── levn@0.3.0 (type-check@0.3.2, prelude-ls@1.1.2)
├── optionator@0.8.1 (fast-levenshtein@1.1.4, type-check@0.3.2, wordwrap@1.0.0, deep-is@0.1.3, prelude-ls@1.1.2)
├── json-stable-stringify@1.0.1 (jsonify@0.0.0)
├── shelljs@0.6.1
├── require-uncached@1.0.2 (resolve-from@1.0.1, caller-path@0.1.0)
├── mkdirp@0.5.1 (minimist@0.0.8)
├── glob@7.0.6 (inherits@2.0.3, fs.realpath@1.0.0, once@1.4.0, inflight@1.0.5, minimatch@3.0.3)
├── concat-stream@1.5.2 (inherits@2.0.3, typedarray@0.0.6, readable-stream@2.0.6)
├── is-my-json-valid@2.13.1 (jsonpointer@2.0.0, generate-function@2.0.0, xtend@4.0.1, generate-object-property@1.2.0)
├── inquirer@0.12.0 (ansi-regex@2.0.0, strip-ansi@3.0.1, ansi-escapes@1.4.0, rx-lite@3.1.2, through@2.3.8, cli-width@2.1.0, figures@1.7.0, run-async@0.1.0, string-width@1.0.2, readline2@1.0.1, cli-cursor@1.0.2)
├── espree@3.1.7 (acorn-jsx@3.0.1, acorn@3.3.0)
├── js-yaml@3.6.1 (esprima@2.7.3, argparse@1.0.7)
├── file-entry-cache@1.3.1 (object-assign@4.1.0, flat-cache@1.2.1)
├── table@3.7.8 (slice-ansi@0.0.4, tv4@1.2.7, xregexp@3.1.1, strip-ansi@3.0.1, string-width@1.0.2, bluebird@3.4.6)
├── es6-map@0.1.4 (d@0.1.1, es6-symbol@3.1.0, event-emitter@0.3.4, es6-iterator@2.0.0, es6-set@0.1.4, es5-ext@0.10.12)
├── escope@3.6.0 (esrecurse@4.1.0, es6-weak-map@2.0.1)
└── lodash@4.15.0

It also happens with the v3.x alpha release.

superkhau commented 8 years ago

That is interesting, can you try running the examples at https://github.com/strongloop/loopback-example-kv-connectors and let me know if they work?

penguinpowernz commented 8 years ago

Yep that works. Why though? I notice that's running 3.0.0-alpha.5 of loopback, is the kv-redis connector only compatible with the 3.x versions? I haven't had any success swapping out loopback-connector-redis for loopback-connector-kv-redis in an established app, but I downgraded that to 2.34.1 from 3.0.0-alpha.5.

superkhau commented 8 years ago

It should work for both versions (althought as you can see from my example, I'm using the latest master on GH -- 3.0.0-alpha.5). Would you like to help update the examples? We need it working for all versions (its WIP ATM -- almost release time after we work out the gremlins as you discovered).

penguinpowernz commented 8 years ago

I downgraded to 2.34.1 in the redis-lb2x and it still boots. I think the kv-redis connector doesn't work as I expect it to (i.e. doesn't want to store PersistedModel) - judging by the Color model in there. Trying to find all PersistedModels (/api/animals) results in this error:

{
  "error": {
    "name": "Error",
    "status": 500,
    "message": "Cannot call Animal.find(). The find method has not been setup. The PersistedModel has not been correctly attached to a DataSource!",
    "stack": "Error: Cannot call Animal.find(). The find method has not been setup. The PersistedModel has not been correctly attached to a DataSource!\n    at throwNotAttached (/home/robert/src/test2/loopback-example-kv-connectors/redis-lb2x/node_modules/loopback/lib/persisted-model.js:68:11)\n    at Function.find (/home/robert/src/test2/loopback-example-kv-connectors/redis-lb2x/node_modules/loopback/lib/persisted-model.js:256:5)\n    at SharedMethod.invoke (/home/robert/src/test2/loopback-example-kv-connectors/redis-lb2x/node_modules/loopback/node_modules/strong-remoting/lib/shared-method.js:263:25)\n    at HttpContext.invoke (/home/robert/src/test2/loopback-example-kv-connectors/redis-lb2x/node_modules/loopback/node_modules/strong-remoting/lib/http-context.js:389:12)\n    at phaseInvoke (/home/robert/src/test2/loopback-example-kv-connectors/redis-lb2x/node_modules/loopback/node_modules/strong-remoting/lib/remote-objects.js:654:9)\n    at runHandler (/home/robert/src/test2/loopback-example-kv-connectors/redis-lb2x/node_modules/loopback/node_modules/loopback-phase/lib/phase.js:135:5)\n    at iterate (/home/robert/src/test2/loopback-example-kv-connectors/redis-lb2x/node_modules/loopback/node_modules/loopback-phase/node_modules/async/lib/async.js:146:13)\n    at Object.async.eachSeries (/home/robert/src/test2/loopback-example-kv-connectors/redis-lb2x/node_modules/loopback/node_modules/loopback-phase/node_modules/async/lib/async.js:162:9)\n    at runHandlers (/home/robert/src/test2/loopback-example-kv-connectors/redis-lb2x/node_modules/loopback/node_modules/loopback-phase/lib/phase.js:144:13)\n    at iterate (/home/robert/src/test2/loopback-example-kv-connectors/redis-lb2x/node_modules/loopback/node_modules/loopback-phase/node_modules/async/lib/async.js:146:13)\n    at /home/robert/src/test2/loopback-example-kv-connectors/redis-lb2x/node_modules/loopback/node_modules/loopback-phase/node_modules/async/lib/async.js:157:25\n    at /home/robert/src/test2/loopback-example-kv-connectors/redis-lb2x/node_modules/loopback/node_modules/loopback-phase/node_modules/async/lib/async.js:154:25\n    at execStack (/home/robert/src/test2/loopback-example-kv-connectors/redis-lb2x/node_modules/loopback/node_modules/strong-remoting/lib/remote-objects.js:493:7)\n    at RemoteObjects.execHooks (/home/robert/src/test2/loopback-example-kv-connectors/redis-lb2x/node_modules/loopback/node_modules/strong-remoting/lib/remote-objects.js:497:10)\n    at phaseBeforeInvoke (/home/robert/src/test2/loopback-example-kv-connectors/redis-lb2x/node_modules/loopback/node_modules/strong-remoting/lib/remote-objects.js:650:10)\n    at runHandler (/home/robert/src/test2/loopback-example-kv-connectors/redis-lb2x/node_modules/loopback/node_modules/loopback-phase/lib/phase.js:135:5)"
  }
}
superkhau commented 8 years ago

Did you try with KVModel? Not supposed to use PersistedModel. See https://github.com/strongloop/loopback-example-kv-connectors/blob/master/redis-lb2x/common/models/color.json#L3

penguinpowernz commented 8 years ago

Yes the KVModel works... but now I realize that this is not what I want. I want a persisted model, persisted in Redis so went back to loopback-connector-redis.

Using your example redis-lb2x app with 2.34.1 works fine, so I don't know what the loopback generator does differently.

superkhau commented 8 years ago

I will close issue then. Please open a new issue if you are still running into issues.