fetch-mock icon indicating copy to clipboard operation
fetch-mock copied to clipboard

fetch-mock not working after update to Node v18

Open mfernandes-alcumus opened this issue 2 years ago • 3 comments

Fetch is not getting mocked after updating to node v18

mfernandes-alcumus avatar Aug 22 '23 14:08 mfernandes-alcumus

@mfernandes-alcumus Hey, I faced the same issue when migrating from Node v16 to Node v18.

Use the --no-experimental-fetch flag when running tests to disable the global fetch, ensuring that fetch-mock works as expected.

You can read about why you are facing this issue here.

https://nodejs.org/en/blog/announcements/v18-release-announce#fetch-experimental

The global fetch in Node.js 18 is labeled as "experimental." This means it might not be fully stable or might have behaviors that differ from other fetch implementations. By using the --no-experimental-fetch flag, you're essentially reverting to the previous behavior, where there's no global fetch, making libraries like fetch-mock behave as expected.

metart43 avatar Sep 12 '23 11:09 metart43

thanks @metart43 that is very helpful

mfernandes-alcumus avatar Sep 21 '23 07:09 mfernandes-alcumus

fetch is stable in Node.js 21 https://nodejs.org/en/blog/announcements/v21-release-announce#stable-fetchwebstreams, not experimental anymore

peterholak avatar Jan 24 '24 11:01 peterholak

For anyone wanting to use fetch-mock with native fetch please give fetch-mock@10 a try. It's a big refactor so please try it out and raise issues if you have any problems.

wheresrhys avatar Jun 15 '24 18:06 wheresrhys