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.

encoding not found when requiring node-fetch

See original GitHub issue

For some reason, when you try to package a function that requires node-fetch the encoding module isn’t found.

We need to determine if:

  • This is a problem with node-fetch, or a consumption concern
  • or if we are missing this dep for some reason, or if we are requiring that it exist, but it doesn’t really have to.
  • Decide if we make an exception for this very common scenario, or improve output when this pitfall is hit.

Examples in the wild:

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
ehmickycommented, Sep 19, 2019

Just for reference, this problem is not specific to node-fetch. It applies to any require("moduleName") that is inside a conditional block or a try/catch (such as encoding) and is not declared in optionalDependencies.

This has been fixed in node-fetch@3 but this has not been released yet.

1reaction
cliffasauruscommented, Apr 30, 2019

It looks like a function is requiring ./dist/react-hot-loader.production.min.js but it isn’t found when bundling the function. Ensuring that is available, or ensuring that your function doesn’t attempt to load that module during runtime is the solution. Are you perhaps shipping your site bundle as a function?

I got it now. The bundling seems to have traversed one level up and got the .babelrc where I declared a plugin of react-hot-loader. I fixed it by declaring a separate .babelrc inside the functions folder

Read more comments on GitHub >

github_iconTop Results From Across the Web

NPM warning node-fetch @2.6.7 Requires a peer of encoding ...
peer dependency means that it need the library and you must install that dependency by yourself: npm i encoding@0.1.0.
Read more >
Error: Can't resolve 'encoding' when deploying Next.js ...
Run yarn add encoding in your project directory · Clear the next directory in your project by running rm -rf .next in the...
Read more >
node-fetch - npm
A light-weight module that brings Fetch API to node.js. Latest version: 3.3.0, last published: 2 months ago. Start using node-fetch in your ...
Read more >
Errors | Node.js v19.3.0 Documentation
For all EventEmitter objects, if an 'error' event handler is not provided, the error will be thrown, causing the Node.js process to report...
Read more >
How to use the node-fetch.Headers function in node-fetch | Snyk
Use Snyk Code to scan source code in minutes - no build needed - and fix issues ... const { URL } =...
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