Error using $fetch.create using CJS modules.
See original GitHub issueI was working in a Nuxt2 app using ohmyfetch
in the background with a home-made module, but the Nuxt2 app displays me that the$fetch
export has not the method create
, so I investigate and I found that the CJS module (what it was imported by Webpack after the bundle process) it not exports the method.
Steps to reproduce the error
- Create a new JS proyect with the
ohmyfetch
dependency. - Create a
index.js
file with the following content.
const { $fetch } = require('ohmyfetch')
const scopedFetch = $fetch.create({});
- Try to run the file.
What I was expected
It should not thrown an error.
Error description
const scopedFetch = $fetch.create({});
^
TypeError: $fetch.create is not a function
at Object.<anonymous> (/home/bantonio/PhpstormProjects/test-ohmyfetch/index.js:3:28)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:13 (5 by maintainers)
Top Results From Across the Web
Loading node-fetch@3 in CJS and ESM · Issue #1279 - GitHub
I'm having problems with ESM and TypeScript If you have decided to make your project ESM ( "type": "module" in your package. json),...
Read more >require() of ES modules is not supported when importing node ...
js file has nothing but the import of node-fetch and it gives me an error message. What am I doing wrong? Running Ubuntu...
Read more >Unable to import `node-fetch` in service
I've got code like the following in one of my api service files… import { Connection } from 'jsforce' import fetch from 'node-fetch'...
Read more >node-fetch Error [ERR_REQUIRE_ESM]: require() of ES ...
To solve the node-fetch error "[ERR_REQUIRE_ESM]: require() of ES Module not supported", use a dynamic import to import the node-fetch package or downgrade ......
Read more >Documentation - ECMAScript Modules in Node.js - TypeScript
This has been a very difficult feature to support, since the foundation of the Node.js ecosystem is built on a different module system...
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 FreeTop 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
Top GitHub Comments
@pi0
is there a reason, why the cjs/* import the *,mjs files ?
Would it not be easier, to simply build a cjs version with the following
build.config.ts
?I believe building it in CJS is the only possible solution afaik, because we cannot load mjs, without being async…
I’m still getting this in 1.0.0 and I’m not sure what the issue is