New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to use fetch-mock as ES6 import #631
Comments
I think with version 2.x of node-fetch you are able to use require. |
I'm getting the exactly same error and I'm using the exactly same version here. Tried to import directly the functions needed, but still couldn't find a way to fix it. |
@BadIdeaException that happens because on server.js fetch-mock is importing node-fetch using require, which on version 3 is not supported anymore. To fix it, downgrade your node-fetch version to 2.6.7. That will solve the problem temporarily. Still server.js might need to change the way it's importing to support node-fetch 3+. |
Thanks, I'll look into that. I ended up switching to nock instead. I do like the fetch-mock API better, but since node-fetch 3.0.0 introduced breaking changes, and it can't be long now before fetch comes built-in to NodeJS, I'm not too keen on downgrading. Hopefully this will get fixed in fetch-mock quickly. |
I guess the |
Does this work? It seems |
Still getting the following error using this in an ESM setup:
Since ESM has been available in Node for quite some time now, I think such issues should be treated as a priority. Will try |
Same problem here. Any solution? |
This fixed it for me. Downgrading to version 2 with |
I can't import fetch-mock using NodeJS 17.6.0 and fetch-mock 9.11.0.
The following minimal example
index.mjs
:package.json
:produces
It seems that it's trying to import the CommonJS version, so as per the documentation about importing the correct version, I tried replacing the import with the esm version specifically:
Now I get:
Okay, sure, let's try that:
Still no dice:
I found issue 446 and issue 481 which seemed similar, and tried downgrading to mock-fetch version 8, but I see the same errors.
And now I don't know what more to try. What am I doing wrong here? Would be grateful for a nudge in the right direction.
The text was updated successfully, but these errors were encountered: