TypeError:无法读取未定义的属性'render'

时间:2017-06-22 23:14:00

标签: node.js microsoft-graph

当我运行microsoft graph api的node.js代码示例时,我得到了这个:

https://developer.microsoft.com/en-us/graph/graph/quick-start

有谁知道如何修复它?

由于

节点:6.11.0 NPM:5.0.3

> nodejs-microsoft-graph-connect@2.0.0 start C:\Users\me\Desktop\Apps\AI-Work
> mocha ./tests/confTest.js && node ./bin/www



  ADAL
    √ Checking clientID and clientSecret in config.js


  1 passing (14ms)

{"name":"AzureAD: OIDC Passport Strategy","hostname":"DESKTOP-Q841CUJ","pid":67868,"level":40,"msg":"Production environments should always validate the issuer.","time":"2017-06-22T23:06:46.715Z","v":0}
{"name":"AzureAD: OIDC Passport Strategy","hostname":"DESKTOP-Q841CUJ","pid":67868,"level":40,"msg":"Using http for redirectUrl is not recommended, please consider using https","time":"2017-06-22T23:06:46.720Z","v":0}

Listening on port 3000
GET / 304 160.625 ms - -
GET /stylesheets/style.css 304 5.216 ms - -
GET /img/favicon.ico 304 1.561 ms - -
GET /login 302 661.892 ms - 0
GET /token?code=------------------------------------------------------------------------------ 200 1672.604 ms - 2020
GET /stylesheets/style.css 304 2.921 ms - -
GET /img/favicon.ico 304 2.740 ms - -
C:\Users\me\Desktop\Apps\AI-Work\routes\index.js:139
  res.render('error', {
     ^

TypeError: Cannot read property 'render' of undefined
    at renderError (C:\Users\me\Desktop\Apps\AI-Work\routes\index.js:139:6)
    at graphHelper.getProfilePhoto (C:\Users\me\Desktop\Apps\AI-Work\routes\index.js:73:19)
    at request.get.set.end (C:\Users\me\Desktop\Apps\AI-Work\utils\graphHelper.js:35:6)
    at Request.callback (C:\Users\me\Desktop\Apps\AI-Work\node_modules\superagent\lib\node\index.js:688:3)
    at C:\Users\me\Desktop\Apps\AI-Work\node_modules\superagent\lib\node\index.js:883:18
    at IncomingMessage.<anonymous> (C:\Users\me\Desktop\Apps\AI-Work\node_modules\superagent\lib\node\parsers\json.js:16:7)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nodejs-microsoft-graph-connect@2.0.0 start: `mocha ./tests/confTest.js && node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nodejs-microsoft-graph-connect@2.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\me\AppData\Roaming\npm-cache\_logs\2017-06-22T23_07_03_252Z-debug.log

1 个答案:

答案 0 :(得分:0)

这与我在此处回复的问题类似:https://stackoverflow.com/a/44464060/2517012

我们已向Microsoft的相应团队报告了这些问题,他们正在更新样本。

对于此问题,renderError()有两个参数 - 错误和响应对象。您在res.render()上进行了未定义的渲染,可能是因为只使用一个参数调用了renderError。正如我在上面链接的答案中提到的,我建议设置断点以查看为什么要调用renderError方法。