Skip to content
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

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

Closed
miii opened this issue Nov 12, 2020 · 7 comments
Closed

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

miii opened this issue Nov 12, 2020 · 7 comments
Labels
dependencies Pull requests that update a dependency file

Comments

@miii
Copy link

miii commented Nov 12, 2020

@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
Copy link
Member

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.

@lmiller1990 lmiller1990 added the dependencies Pull requests that update a dependency file label Nov 12, 2020
@sceee
Copy link

sceee commented Feb 2, 2021

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
Copy link
Member

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
Copy link

sceee commented Feb 11, 2021

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
Copy link
Contributor

shayneo commented May 11, 2021

also seeing this in a yarn monorepo setup

@lmiller1990
Copy link
Member

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
Copy link

bonham commented Jan 1, 2023

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

  • created a vanilla vue project with yarn create vite and included the unit test option
  • after installing packages with yarn I tried to run unit tests with yarn vitest --environment jsdom --root src/
  • Result: Error: @vue/test-utils tried to access @vue/compiler-dom, but it isn't declared in its dependencies

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file
Projects
None yet
Development

No branches or pull requests

5 participants