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

utils.ensurePackageInstalled is not compatible with yarn PnP #899

Closed
6 tasks done
pietrovismara opened this issue Mar 6, 2022 · 5 comments · Fixed by #1667 or #4657
Closed
6 tasks done

utils.ensurePackageInstalled is not compatible with yarn PnP #899

pietrovismara opened this issue Mar 6, 2022 · 5 comments · Fixed by #1667 or #4657

Comments

@pietrovismara
Copy link

pietrovismara commented Mar 6, 2022

Describe the bug

Trying to run vitest in a package of a yarn monorepo will cause the following error:

 MISSING DEP  Can not find dependency 'vite'

✖ Do you want to install vite? … no

I already have vite installed and apparently the issue is caused by this line:

if (isPackageExists(dependency))

The local-pkg is not compatible with yarn PnP, as confirmed by this issue.

As far as I understand it, it should be enough to call isPackageExists with a second options parameters like this:

isPackageExists(dependency, { paths: [ process.cwd() ] })

I already tested this solution locally with a fork of local-pkg and it works.

Reproduction

The issue is already confirmed.

System Info

System:
    OS: Linux 5.10 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: x64 Intel [redacted]
    Memory: 2.72 GB / 7.63 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 16.13.2 - /usr/bin/node
    Yarn: 3.1.1 - /usr/bin/yarn
    npm: 8.1.2 - /usr/bin/npm

Used Package Manager

yarn

Validations

@IgnusG
Copy link
Contributor

IgnusG commented Mar 31, 2022

I additionally had the following problem which I think stems from vitest requiring happy-dom through local-pkg:

Error: local-pkg tried to access happy-dom, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: happy-dom (via "happy-dom/package.json")

const { Window } = await importModule('happy-dom') as typeof import('happy-dom')

After patching vitest with @pietrovismara's fix I had to add the following to yarnrc.yml though it feels very wrong since it feels like vitest should need to be specified and not local-pkg for extension. However fixed the issue.

  "local-pkg@*": # This is required for vitest as it accesses happy-dom through local-pkg on its behalf
    dependencies:
      "happy-dom": "*"

@eudinnou
Copy link

we are looking to migrate from jest to vitest but we have the same issue with a yarn2 monorepo

@fwouts
Copy link

fwouts commented May 4, 2022

For anyone trying to use Vitest with pnpm in a monorepo, the following .npmrc config seems to work as a workaround:

hoist-pattern[]="vite"

@ekeijl
Copy link

ekeijl commented Jul 18, 2022

The issue should still be fixed, but as a temporary solution you can add this to .yarnrc.yml:

pnpMode: "loose"

packageExtensions:
    "vite@*": 
        dependencies:
            "supports-color": "*"
    "debug@*": 
        dependencies:
            "supports-color": "*"

@jfirebaugh
Copy link

Also happens with pnpm and hoist=false in .npmrc.

Error looks like:

Error: Cannot find package 'jsdom' imported from [REDACTED]/node_modules/.pnpm/local-pkg@0.4.3/node_modules/local-pkg/index.mjs

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants