Tuesday 30 May 2017

Cannot read property '_header' of undefined in finalHandler node module

I can't seem to find a solution to my problem. I am trying to startup my nodeJS/expressJS app but am receiving an error upon "npm start".

The Error & Stacktrace:

    /Users/jmccreary/Documents/NewHireSite/node_modules/finalhandler/index.js:94
    if (!err && res._header) {
                   ^

TypeError: Cannot read property '_header' of undefined
    at /Users/jmccreary/Documents/NewHireSite/node_modules/finalhandler/index.js:94:20
    at /Users/jmccreary/Documents/NewHireSite/node_modules/express/lib/router/index.js:635:15
    at next (/Users/jmccreary/Documents/NewHireSite/node_modules/express/lib/router/index.js:210:14)
    at Function.handle (/Users/jmccreary/Documents/NewHireSite/node_modules/express/lib/router/index.js:174:3)
    at Function.handle (/Users/jmccreary/Documents/NewHireSite/node_modules/express/lib/application.js:174:10)
    at app (/Users/jmccreary/Documents/NewHireSite/node_modules/express/lib/express.js:38:9)
    at Object.<anonymous> (/Users/jmccreary/Documents/NewHireSite/app.js:101:25)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/jmccreary/Documents/NewHireSite/bin/www:7:11)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:427:7)

The Offending Code in FinalHandler Module:

  function finalhandler (req, res, options) {
  var opts = options || {}
  console.log("The req is: ", req);
  console.log("The res is: ", res);

  // get environment
  var env = opts.env || process.env.NODE_ENV || 'development'

  // get error callback
  var onerror = opts.onerror

  return function (err) {
    var headers
    var msg
    var status

    // ignore 404 on in-flight response
    if (!err && res._header) {
      debug('cannot 404 after headers sent')
      return
    }
    ...

From my console.log()'s as shown, the output is below:

 The req is:  Authenticator {
  _key: 'passport',
  _strategies: { session: SessionStrategy { name: 'session' } },
  _serializers: [],
  _deserializers: [],
  _infoTransformers: [],
  _framework: 
   { initialize: [Function: initialize],
     authenticate: [Function: authenticate] },
  _userProperty: 'user',
  Authenticator: [Function: Authenticator],
  Passport: [Function: Authenticator],
  Strategy: { [Function: Strategy] Strategy: [Circular] },
  strategies: { SessionStrategy: { [Function: SessionStrategy] super_: [Object] } } }
 The res is:  undefined

I am able to run the tutorial's source code just fine, and it has the same modules as my app, which is nearly identical (except for a www/bin file upon npm start command). I've tried removing other modules and moving things around in my app.js file to no avail.

Any pointers or help would be much appreciated. Thank you!



via James McCreary

No comments:

Post a Comment