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?
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