vuejs / test-utils

Vue Test Utils for Vue 3
https://test-utils.vuejs.org
MIT License
1.04k stars 244 forks source link

Yarn 2 issues, @vue/test-utils tried to access @vue/compiler-dom #245

Closed miii closed 3 years ago

miii commented 3 years ago

@vue/compiler-dom is not listed as a dependency which causes Yarn 2 to break.

@vue/test-utils tried to access @vue/compiler-dom, but it isn't declared in its dependencies;
This makes the require call ambiguous and unsound.

https://github.com/vuejs/vue-test-utils-next/blob/8a1f348969ffadfe1b35de746f0c27c020ee074c/src/utils/compileSlots.ts#L1

Temporary solution:

# <project root>/.yarnrc.yml
packageExtensions:
  "@vue/test-utils@2.*":
    dependencies:
      "@vue/compiler-dom": "*"
lmiller1990 commented 3 years ago

Hi! I have not tried out yarn 2 yet.

Can we just add @vue/compiler-dom as a dependency to fix this?

If you want to send a PR, I will do a release this weekend so you can use VTU with yarn 2.

sceee commented 3 years ago

I am seeing the same issue with npm (I am in a vue2 project):

 ERROR  Failed to compile with 1 error

 error  in ./node_modules/@vue/test-utils/dist/vue-test-utils.esm-bundler.js

Module not found: Error: Can't resolve '@vue/compiler-dom' in 'C:\proj\node_modules\@vue\test-utils\dist'

So I guess @vue/compiler-dom should be added as dependency.

Installing it using npm i -D @vue/compiler-dom seems to solve the issue but I can unfortunately not be 100% sure as I now did run in the next issue (unrelated to this).

@lmiller1990 if you think it's correct to add this, I can submit a PR for this.

lmiller1990 commented 3 years ago

Vue 2 was not a monorepo and does not have a @vue/compiler-dom - have you got the right version of test utils? test-utils v1 is for Vue 2, test-utils v2 is for Vue 3 (confusing, yes - Vue 1 never had any testing utils, so that's why).

Either way if it is as simple as adding the dependency here, please go for it! yarn 2 compat would be great.

sceee commented 3 years ago

Ok, I think I was getting confused with the versioning. My fault, sorry. I am now on Vue2, @vue/test-utils 1 and webpack 4. So far so good, everything works (except I ideally would like to upgrade to webpack 5) but when doing so, I face quite some issues.

Anyway, as I'm on Vue 2, it definitely does not relate to here. I think I came across this particular issue when trying to upgrade to webpack 5 and fix some of the errors but I unfortunately can't remember what exactly I did. Probably I tried to use vue-test-utils-next in the Vue2 project (because I thought it might solve some issues) and that was the reason I got this error.

So I think in my case it was just a misconfiguration by myself.

Therefore I would also not just add the dependency as I wrote above.

shayneo commented 3 years ago

also seeing this in a yarn monorepo setup

lmiller1990 commented 3 years ago

I am using this in Cypress yarn monorepo and it's working fine for me there.

We should fix the yarn 2 issue first, and figure out if there are any other issues (yarn 1, etc) elsewhere. Thanks for the PR @shayneo, any chance you can confirm it's working in yarn 2?

bonham commented 1 year ago

The issue is still there with yarn version 3.3.1 and @vue/test-utils 2.2.6 How I did it:

Looks like it is not fully compatible with yarn plug and play as described in yarn docs. Switching to pnp loose option seems to work around the issue.

My env:

yarn 3.3.1 node 16.19.0

├─ @rushstack/eslint-patch@npm:1.2.0 ├─ @vitejs/plugin-vue@npm:4.0.0 ├─ @vue/eslint-config-prettier@npm:7.0.0 ├─ @vue/test-utils@npm:2.2.6 ├─ eslint-plugin-vue@npm:9.8.0 ├─ eslint@npm:8.31.0 ├─ jsdom@npm:20.0.3 ├─ prettier@npm:2.8.1 ├─ vite-sb-tm-test@workspace:. ├─ vite@npm:4.0.3 ├─ vitest@npm:0.26.2 ├─ vue-router@npm:4.1.6 └─ vue@npm:3.2.45