-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"TypeError: Cannot create proxy with a non-object as target or handler" when importing node module with a Proxy #6115
Comments
Thanks for the reproduction. It looks like this is because vitest/packages/vite-node/src/client.ts Lines 547 to 553 in 5d6d801
First of all, Technically, the same error can happen in innocent-looking async/await code outside of Vitest, so maybe // node repro.mjs
async function main() {
// "await" implicitly checks `mod.default.then`
await import("not-a-log").then(mod => mod.default);
}
main();
// or maybe this looks more innocent
async function main2() {
const { default: logger } = await import("not-a-log");
return logger;
}
// "await" implicitly checks `logger.then`
const logger = await main2(); One way to save error this on Vitest is to fix this TODO vitest/packages/vite-node/src/client.ts Lines 526 to 528 in 5d6d801
or you can try disabling this "interop" entirely by export default defineConfig({
test: {
deps: {
interopDefault: false,
}
},
}) |
Thanks for the deep dive & explanation! I filed an issue upstream: jimmywarting/not-a-log#2. |
I am not sure if this is a bug in Vitest. I don't think it's possible to support this case because // mod.ts
export const then = () => {}
// index.ts
await import('./mod.ts') |
Named export of Since vitest/packages/vite-node/src/client.ts Lines 526 to 528 in 5d6d801
|
I'm closing this for the same reason as #5122 and upstream vitejs/vite#18328 |
Describe the bug
When
import
ing from an installed npm package such asnot-a-log
that uses aProxy
, Vitest crashes with:Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-keoxtv
I also set up a full reproduction here: https://github.com/JoshuaKGoldberg/repros/tree/vitest-proxy-not-a-log
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: