Open bernardocorbella opened 10 months ago
We are seeing the same issue, in the exact same context.
did you guys find a solution to this?
We patched @vue/test-utils so that it would import vue instead of @vue/compat. Inelegant but it works.
(We use patch-package
to do this).
diff --git a/node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js b/node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js
index 8ca89e9..ef246d0 100644
--- a/node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js
+++ b/node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js
@@ -7,7 +7,7 @@
'use strict';
-var Vue = require('vue');
+var Vue = require('@vue/compat');
var compilerDom = require('@vue/compiler-dom');
var serverRenderer = require('@vue/server-renderer');
Is it possible to use Vite with Vue Compat?
Is it possible to use Vite with Vue Compat? Yes, we successfully use it with vue compat.
With Vitest, aliasing @vue/compat to vue seems to work fine when the vue imports originate from the project's direct source code, but not always when it comes from the dependencies, as exemplified here with @vue/test-utils
. The imports have to be manually patched in the dependencies' source code until this bug is fixed.
Describe the bug
When using the build
@vue/compat
and installing it according to the migration guide (ie: using alias in vite), the tests fail with the following message:This happens when you try to render a component with a slot.
Looking around, I have found this is a very similar issue than: https://github.com/vitest-dev/vitest/issues/1886. Following the instructions here, I have managed to add
@vue/test-utils
to the inlined dependencies (as you can see in the reproduction).The issue happens whenever adding
@testing-library/vue
. The tests usingtesting-library
now also fail due to the same reason. At this point I have tried multiple combinations of inlining dependencies without much luck.If I manually edit the
node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js
file and change thevue
import to@vue/compat
, both of the tests work.I suspect the solution might be simpler and would also happily contribute in case its needed.
Thank you!
Reproduction
https://github.com/bernardocorbella/vue-compat-vite-slot-error
You can see the test file in which one test passes and one fails.
System Info
Used Package Manager
pnpm
Validations