vuejs / test-utils

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

Bug with yarn berry: @vue/test-utils tried to access @vue/compiler-dom #2107

Open stefpb opened 1 year ago

stefpb commented 1 year ago

Describe the bug with yarn berry i have an issue with the version 2.4.0.


 RUN  v0.32.2 /app

 ❯ example.test.ts (0)

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  example.test.ts [ example.test.ts ]
Error: @vue/test-utils tried to access @vue/compiler-dom (a peer dependency) but it isn't provided by your application; this makes the require call ambiguous and unsound.

Required package: @vue/compiler-dom (via "@vue/compiler-dom/package.json")
Required by: @vue/test-utils@virtual:0460f86c7587ee75dac643681550c044e8047ba46e219a5baac054fc0fea2d0af97a9bd3fe4b22de0884797215e0a1a4368bb60f9ef7087a69c4008789f4e032#npm:2.4.0 (via /app/.yarn/__virtual__/@vue-test-utils-virtual-4aca422d8c/0/cache/@vue-test-utils-npm-2.4.0-7d32a4f2ce-28b9628cf8.zip/node_modules/@vue/test-utils/dist/vue-test-utils.esm-bundler.mjs)
Ancestor breaking the chain: app@workspace:.

 ❯ makeError .pnp.cjs:11264:34
 ❯ resolveToUnqualified .pnp.cjs:12930:21
 ❯ Object.resolveToUnqualified .pnp.cjs:13173:26
 ❯ resolve$1 .pnp.loader.mjs:1977:31

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: {
  "code": "MODULE_NOT_FOUND",
  "data": {
    "brokenAncestors": [
      {
        "name": "app",
        "reference": "workspace:.",
      },
    ],
    "dependencyName": "@vue/compiler-dom",
    "issuer": "/app/.yarn/__virtual__/@vue-test-utils-virtual-4aca422d8c/0/cache/@vue-test-utils-npm-2.4.0-7d32a4f2ce-28b9628cf8.zip/node_modules/@vue/test-utils/dist/vue-test-utils.esm-bundler.mjs",
    "issuerLocator": {
      "name": "@vue/test-utils",
      "reference": "virtual:0460f86c7587ee75dac643681550c044e8047ba46e219a5baac054fc0fea2d0af97a9bd3fe4b22de0884797215e0a1a4368bb60f9ef7087a69c4008789f4e032#npm:2.4.0",
    },
    "request": "@vue/compiler-dom/package.json",
  },
  "pnpCode": "MISSING_PEER_DEPENDENCY",
}
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

 Test Files  1 failed (1)
      Tests  no tests
   Start at  16:15:05
   Duration  894ms (transform 51ms, setup 0ms, collect 0ms, tests 0ms, environment 198ms, prepare 124ms)

To Reproduce https://github.com/stefpb/vue-test-utils-yarn-issue

Expected behavior test-runner passed

Related information: Look to my minimal repo.

cexbrayat commented 1 year ago

The peer dependency is marked as optional using peerDependenciesMeta (see https://github.com/vuejs/test-utils/blob/main/package.json#L72-L74)

Maybe that should not be the case as it used to compile slots (I don't remember why it was marked optional).

Would you like to open a PR to remove the optional from the pakage.json file and see if that fixes the issue? We would greatly appreciate it

stefpb commented 1 year ago

Thanks for your answer. Now it looks like that this commit https://github.com/vuejs/test-utils/commit/b08b1f04681c703d1fd14f07272337f4e9ff2bfc leads to this problem. But yes, how i can double check this?

but now i don't know how i change this line https://github.com/stefpb/vue-test-utils-yarn-issue/blob/main/Dockerfile#L21 to say yarn to load the library from there :/

cexbrayat commented 1 year ago

Yes, it's hard to test. But I think you can safely open a PR to remove compiler-dom from peerDependencies and peerDependenciesMeta, as the dependency is in fact mandatory.

stefpb commented 1 year ago

Unfortantely this Pull-Request (https://github.com/vuejs/test-utils/pull/2114) is not solving #2107. With 2.4.1 i have still this issue: https://github.com/stefpb/vue-test-utils-yarn-issue/tree/main

My intention was to revert https://github.com/vuejs/test-utils/commit/b08b1f04681c703d1fd14f07272337f4e9ff2bfc as you can see in https://github.com/vuejs/test-utils/pull/2113. Could you also restore the optional dependencies to the original state, as was intended?

lmiller1990 commented 1 year ago

If this fixes it, I say we go for it. Can you make a fresh PR @stefpb? I don't really know the intricacies of optionalDeps vs peer etc, it sounds like this is something you know well and have a fix for.

stefpb commented 1 year ago

PR has been submitted. If a new release is available, I'll test that version here: https://github.com/stefpb/vue-test-utils-yarn-issue/blob/main/Dockerfile#L21

RyanThomas73 commented 3 months ago

Any updates on planned fixes for this?

Checking the current package.json @vue/compiler-dom is still listed as a devDependency in lieu of either dependency or peerDependency

urkle commented 2 months ago

In order to fix this issue with Yarn (in PNP mode) I had to add the following to my .yarnrc.yml to fake the dependencies so that things work.

packageExtensions:
  "@vue/test-utils@*":
    dependencies:
      "@vue/compiler-dom": "3.3.13"
      "@vue/server-renderer": "3.3.13"