question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property '0' of undefined

See original GitHub issue

Hi I have a snippet like this (also using express-promise-router from master)

const router = require('express-promise-router')()
router.get(function(req, res) {
  return foo(req.body).then(bar => res.json(bar))
})
app.use(authstuff())
app.use(`/foo`, router)

Running tests I get

     TypeError: Cannot read property '0' of undefined
      at Route.instanceToWrap.(anonymous function) [as get] (node_modules/express-promise-router/lib/express-promise-router.js:80:87)
      at Function.proto.(anonymous function) (node_modules/express/lib/router/index.js:510:19)
      at Function.instanceToWrap.(anonymous function) [as get] (node_modules/express-promise-router/lib/express-promise-router.js:95:45)
      at Object.module.exports.router (routes/token.js:39:12)
      at Object.<anonymous> (app.js:143:18)
      at require (internal/module.js:11:18)
      at require.connect.then.then (index.js:21:25)
      at tryCatcher (node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (node_modules/bluebird/js/release/promise.js:512:31)
      at Promise._settlePromise (node_modules/bluebird/js/release/promise.js:569:18)
      at Promise._settlePromise0 (node_modules/bluebird/js/release/promise.js:614:10)
      at Promise._settlePromises (node_modules/bluebird/js/release/promise.js:693:18)
      at Async._drainQueue (node_modules/bluebird/js/release/async.js:133:16)
      at Async._drainQueues (node_modules/bluebird/js/release/async.js:143:10)
      at Immediate.Async.drainQueues (node_modules/bluebird/js/release/async.js:17:14)

Maybe I am not using properly or should it be a managed case?

Thanks

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mukacommented, Nov 6, 2017

Hi, thank you for clarifying! I fixed the wrong call on my code and works now.

So the bug is not really a bug 😃

The crash is useful to detect the wrong usage , eventually the user may get warned of the wrong usage, but is really an edge case

Thanks

0reactions
mormahrcommented, Aug 2, 2019

@megamit could you open a new issue? I’m not sure if this is related to the current one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read Property '0' of Undefined in JS
The "Cannot read property '0' of undefined" error occurs when trying to access the 0th index in a variable that stores an undefined...
Read more >
How To Fix Cannot read Property '0' of Undefined in JS
The Solution · Ensure you are using the correct variable · Perform a simple check on your variable before using it to make...
Read more >
Fix: Cannot Read Property '0' of Undefined - Coding Beauty
The “cannot read property '0' of undefined” error occurs when you try to access the 0 index of an array-like variable, but the...
Read more >
How to Prevent the Error: Cannot Read Property '0' of Undefined
If a property of an object is an array, it's possible to accidentally misspell the key or try to access the array through...
Read more >
Javascript Uncaught TypeError: Cannot read property '0' of ...
which means that, when you try to access d[ascii] , you are actually trying to access undefined[0] , hence the error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found