egoist/bundle-require

Imports not working with Vitest

innocenzi opened this issue · 4 comments

I'm using bundle-require in a project, and by default, tests with Vitest fail:

Using esno to run the same code works:

I also discovered that overriding require to use import could make it work:

const result = await bundleRequire({ 
	filepath,
	require: (id: string) => import(id)
})

I'm not familiar with how CJS/ESM work exactly, so I'm unsure if it is a viable workaround or not.

Here is a repository where you can reproduce the issue: https://github.com/innocenzi/vitest-bundle-require-reproduction

Run pnpm test to see the failing test.
Run pnpm cli to see the working CLI call.

I'm thinking https://github.com/egoist/bundle-require/blob/main/src/utils.ts#L53 could be tweaked to make it work with Vitest, the same way it is for Jest?

weird, your repo works for me:

CleanShot 2022-01-01 at 13 09 56@2x

Definitely not working for me.

I'm on Windows 10, node v16.13.1, and the versions are locked by the lockfile. Any clue what would make the difference?

3.0 should work with Vitest

I have since changed my approach so I can't confirm if this works. :/

I'll close the issue so if someone have trouble with that they can create a more specific one. Thanks for your work <3