theKashey / rewiremock

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

Typescript setup Error: Rewiremock: there is no "parent module". Is there two HotModuleReplacementPlugins? #138

Open jamlen opened 2 years ago

jamlen commented 2 years ago

I'm trying to use rewiremock after converting from using rewire in a typescript project.

// ./rewiremock.ts
import rewiremock, {addPlugin, plugins} from 'rewiremock'

rewiremock.overrideEntryPoint(module) // this is important. This command is "transfering" this module parent to rewiremock
addPlugin(plugins.nodejs)
// we need webpack aliases
addPlugin(plugins.webpackAlias)
// and all stub names would be a relative
addPlugin(plugins.relative)
// and all stubs should be used. Lets make it default!
addPlugin(plugins.usedByDefault)

export { rewiremock }

// ./test/demo.test.ts
import { rewiremock } from '../rewiremock'

Even just importing is enough for the error to occur.

This has the same error as https://github.com/theKashey/rewiremock/issues/137 but a different environment and setup.