Support for ESM #2450
-
Hello @mastermatt ,
This is a reproducible repo. Do you have in plan to release nock as an ESM package? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
@emilioSp I haven't worked with vitest before, or even vite, but there shouldn't be an issue with mixing Nock and vitest as ESM first. My gut is that the error it self is mostly a red herring from how vite monkey patches Node's built-in Hopefully that's enough to get you going. |
Beta Was this translation helpful? Give feedback.
-
We observed also some weird behaviour with vitest. For some reason nock was unable to intercept http request in some situations when using the node.js Instead of using Ex. here's how we kept the typescript type around: import * as https from "https";
import * as http from "http"; const https = require("https") as typeof import("https");
const http = require("http") as typeof import("http"); We have |
Beta Was this translation helpful? Give feedback.
@emilioSp I haven't worked with vitest before, or even vite, but there shouldn't be an issue with mixing Nock and vitest as ESM first.
My gut is that the error it self is mostly a red herring from how vite monkey patches Node's built-in
require
functionality (similar to what Jest does).Thanks for providing the repo, I was able to get things going by ensuring
esModuleInterop
was set to true in your ts-config then fixing the nock import.import nock from 'nock';
Hopefully that's enough to get you going.