fetch-mock
fetch-mock copied to clipboard
fetch-mock not working after update to Node v18
Fetch is not getting mocked after updating to node v18
@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.
thanks @metart43 that is very helpful
fetch is stable in Node.js 21 https://nodejs.org/en/blog/announcements/v21-release-announce#stable-fetchwebstreams, not experimental anymore
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.