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.

[2.6.0] TypeError: Cannot read property 'some' of undefined

See original GitHub issue

Description

Just tried to update apollo-server-express from 2.5.1 → 2.6.0 but it’s failing with the following:

TypeError: Cannot read property 'some' of undefined

  61 | 
> 62 |   const apolloServer = new ApolloServer({
     |                        ^

  at typeDefs.some.typeDef (node_modules/apollo-server-core/src/utils/isDirectiveDefined.ts:8:25)
      at Array.some (<anonymous>)
  at Object.<anonymous>.exports.isDirectiveDefined (node_modules/apollo-server-core/src/utils/isDirectiveDefined.ts:7:12)
  at new ApolloServerBase (node_modules/apollo-server-core/src/ApolloServer.ts:275:12)
  at new ApolloServer (node_modules/apollo-server-express/src/ApolloServer.ts:84:5)

It appears this only happens when importing typeDefs from an SDL file.

Reproduction

Glitch Remix (see server.js line 5, and open the logs)


Hacky Workaround

I modified isDirectiveDefined locally to include a truthiness check and that works, but I’m not sure if that’s a real fix or just masking an actual problem (e.g. should all typeDef objects have a definitions property, or is undefined valid?).

packages/apollo-server-core/src/utils/isDirectiveDefined.ts#L8

  typeDefs.some(typeDef =>
-    typeDef.definitions.some(
+    typeDef.definitions && typeDef.definitions.some(
      definition =>

The code indicates typeDef is of type DocumentNode from graphql/language but I didn’t see DocumentNode in the exported type definitions and ran out of time to chase that further. ¯\_(ツ)_/¯

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
itsnotriskycommented, Jun 26, 2019

Bump this issue for latest 2.6.6

Passing string to typeDefs triggers same error unless wrap it in gql.

2reactions
abernixcommented, May 31, 2019

Fixed in 2.6.1 (#2754), thanks to the both of you! 🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot Read Property of Undefined in JavaScript - Rollbar
What Causes TypeError: Cannot Read Property of Undefined. Undefined means that a variable has been declared but has not been assigned a value....
Read more >
TypeError: Cannot read property 'some' of undefined
javascript - I keep getting this error "TypeError: Cannot read property 'some' of undefined" - Stack Overflow. Stack Overflow for Teams – Start ......
Read more >
typeerror can not read property x of null - YouTube
Join this channel to get access to perks:https://www.youtube.com/channel/UCoSpmr2KNOxjwE_B9ynUmig/joinMy GearCamera ...
Read more >
error: cannot read properties of undefined (reading 'refresh')
Your issue is that your .find() method is returning undefined , so you can't access properties on product such as .name as it...
Read more >
Cannot read properties of undefined (reading 'component')
Uncaught TypeError: Cannot read properties of undefined (reading 'component'). I have gone word blind, I can not see the error. For some reason...
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