encoding not found when requiring node-fetch
See original GitHub issueFor 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:
- Created 4 years ago
- Comments:11 (7 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Just for reference, this problem is not specific to
node-fetch. It applies to anyrequire("moduleName")that is inside a conditional block or atry/catch(such asencoding) and is not declared inoptionalDependencies.This has been fixed in
node-fetch@3but this has not been released yet.I got it now. The bundling seems to have traversed one level up and got the
.babelrcwhere I declared a plugin ofreact-hot-loader. I fixed it by declaring a separate.babelrcinside the functions folder