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.

Node.js - realFetch.call is not a function

See original GitHub issue

Trying to use this in a node.js worker and seeing error realFetch.call is not a function

(node:41803) UnhandledPromiseRejectionWarning: TypeError: realFetch.call is not a function
    at ../node_modules/isomorphic-fetch/fetch-npm-node.js.module.exports (/Users/kevzettler/code/hypeworks/build/webpack:/node_modules/isomorphic-fetch/fetch-npm-node.js:8:1)
    at AssetStore.<anonymous> (/Users/kevzettler/code/hypeworks/build/webpack:/AssetStore.ts:47:30)
    at step (/Users/kevzettler/code/hypeworks/build/0.server.worker.js:36403:23)
    at Object.next (/Users/kevzettler/code/hypeworks/build/0.server.worker.js:36384:53)
    at /Users/kevzettler/code/hypeworks/build/0.server.worker.js:36378:71
    at new Promise (<anonymous>)
    at ./AssetStore.ts.__awaiter (/Users/kevzettler/code/hypeworks/build/0.server.worker.js:36374:12)
    at AssetStore../AssetStore.ts.AssetStore.fetchBinary (/Users/kevzettler/code/hypeworks/build/0.server.worker.js:36443:16)
    at executeAction (/Users/kevzettler/code/hypeworks/build/webpack:/node_modules/mobx/lib/mobx.module.js:928:1)
    at AssetStore.fetchBinary (/Users/kevzettler/code/hypeworks/build/webpack:/node_modules/mobx/lib/mobx.module.js:915:1)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:13
  • Comments:7

github_iconTop GitHub Comments

15reactions
hsiaosiyuan0commented, Dec 2, 2020

I think it’s a bug from node-fetch because it tagged itself as module see here so webpack load its .mjs instead of .js despite their exports have different semantics(scroll former two links to bottom to see the differences)

I guess you may in a isomorphic case, if so try to indicate webpack that node-fetch should be treated as it’s commonjs module via webpack.config.js:

module.exports = {
  // ...
  externals: {
    'node-fetch': 'commonjs2 node-fetch',
  }
};
3reactions
aseurecommented, Feb 25, 2021

Same issue here. We’ve switched to cross-fetch as well which solves the issue for us.

FYI we’ve made it work with isomorphic-fetch with the following configuration but we thought it was too brittle to keep:

module.exports = {
  // ...
  resolve: {
    // ...
    mainFields: ['main', 'module']
  } 
}

With our target setting set to node the default for mainFields was ['module', 'main'].

We’ve also tried to made it per-dependency for both node-fetch and/or isomorphic-fetch by doing the following but this one did not work:

module.exports = {
  // ...
  resolve: {
    // ...
    byDependency: {
      'node-fetch': {
        mainFields: ['main', 'module']
      },
      'isomorphic-fetch': {
        mainFields: ['main', 'module']
      }
    }
  } 
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use the node-fetch.call function in node-fetch | Snyk
To help you get started, we've selected a few node-fetch.call examples, ... { url = 'https:' + url } return realFetch.call(this, url, options)...
Read more >
Isomorphic fetch not working for external requests?
I got node version 5.9.0 and lates express from npm. Can your log what response.json() returns? – Роман Парадеев. May 3, ...
Read more >
Deprecated APIs | Node.js v19.3.0 Documentation
This means there will not be deprecation warnings for Buffer() usage in ... Beginning in Node.js v11.0.0, calling these functions with digest set...
Read more >
isomorphic-fetch - Bountysource
Trying to use this in a node.js worker and seeing error realFetch.call is not a function (node:41803) UnhandledPromiseRejectionWarning: TypeError: ...
Read more >
Cannot use node-fetch in lambda function - Support
I keep getting an error r is not a function on the line when I call fetch . My package.json includes "node-fetch": "^2.6.0"...
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