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.

TypeError: Cannot read property 'fetch' of undefined

See original GitHub issue

When trying to add a RESTDataSource all requests made within this class fail.

Why is this?

The link belows allows you to test the code i wrote. CodeSandBox Link Version: latest

Expected behaviour Being able to make a get Request to the dummy API Actual behaviour Request fails with the following error: "errors": [ { "message": "Cannot read property 'fetch' of undefined", "locations": [ { "line": 2, "column": 3 } ], "path": [ "hello" ], "extensions": { "code": "INTERNAL_SERVER_ERROR", "exception": { "stacktrace": [ "TypeError: Cannot read property 'fetch' of undefined", " at API.<anonymous> (/sandbox/node_modules/apollo-datasource-rest/dist/RESTDataSource.js:158:63)", " at Generator.next (<anonymous>)", " at /sandbox/node_modules/apollo-datasource-rest/dist/RESTDataSource.js:8:71", " at new Promise (<anonymous>)", " at __awaiter (/sandbox/node_modules/apollo-datasource-rest/dist/RESTDataSource.js:4:12)", " at trace (/sandbox/node_modules/apollo-datasource-rest/dist/RESTDataSource.js:153:78)", " at API.<anonymous> (/sandbox/node_modules/apollo-datasource-rest/dist/RESTDataSource.js:196:24)", " at Generator.next (<anonymous>)", " at /sandbox/node_modules/apollo-datasource-rest/dist/RESTDataSource.js:8:71", " at new Promise (<anonymous>)" ] } } } ], "data": { "hello": null } } When logging this in the API class this is the result: API { httpFetch: undefined, memoizedResults: Map {}, baseURL: 'https://jsonplaceholder.typicode.com/' }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
jpouillardcommented, Apr 22, 2021

Same here. If can help :

constructor() {
    super();
    this.baseURL = CHAT_API_HOST;
    this.initialize({} as DataSourceConfig<any>); // <===== this one resolve the issue
  }
3reactions
trevor-scheercommented, Oct 23, 2019

Hey @experimentalPrivateRepos, thanks for submitting an issue (and especially the reproduction!)

I forked your sandbox and found that removing the initialize override, or restoring it to the same behavior as the RESTDataSource resolved the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'fetch' of undefined - Stack Overflow
There is a property called httpFetch which is undefined. When looking in to the restdatasource.js file the line that is throwing the error ......
Read more >
Server Error: Cannot Read Property 'Fetch' of Undefined
Server Error TypeError: Cannot read property 'fetch' of undefined This error happened while generating the page.
Read more >
How to Prevent the TypeError: Cannot Read Property Map of ...
A guide on the root cause of 'cannot read map of undefined' as well as techniques and tools to prevent this error.
Read more >
How to Correctly Fetch Data in React (fix cannot read property ...
This should help you avoid the dreaded " Cannot read property of undefined." Subscribe for more free Coding and Software Dev tips: ...
Read more >
How To Read Property 'Fetch' Of Undefined - Nestjs/Graphql
Whenever you see this TypeError while working with JavaScript Promise, the first step is to inspect the code that was expected to return...
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