theKashey / rewiremock

The right way to mock dependencies in Node.js or webpack environment.
MIT License
490 stars 31 forks source link

Native ESM modules support #79

Open theKashey opened 5 years ago

theKashey commented 5 years ago
damian66 commented 3 years ago

@theKashey any update on this? I am working on a project that has "type": "module" and it does not work for me. As you mentioned, import rewiremock from 'rewiremock'; is not working. I tried rewiremock/node and it does not throw the error at startup, but modules are not mocked

IgnusG commented 2 years ago

Stumbled upon this while trying to integrate local mocking of dependencies in AVA. AVA 4 requires the use of "type": "module" when testing typescript files and rewiremock really seems to dislike that. With the current setup I have control over the ts-node loader. Is there something I could add into the loader that would make rewiremock resolve the parent-child problem?


I saw https://github.com/theKashey/rewiremock/issues/24 where quibble basically solves the problem through the loader but relies on a bit of a hacky global communication and only supports global mocking.

Seems however that based on https://github.com/theKashey/rewiremock/issues/132 it is not possible to dismiss esm anymore as more packages adopt it.