antfu / local-pkg

Get information on local packages.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Yarn PnP support

NMinhNguyen opened this issue · comments

I'm trying to use Vitest and I'm running into an issue with Yarn PnP:

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

Required package: vite (via "vite/package.json")
Required by: local-pkg@npm:0.4.0 (via /Users/minh/dev/project/.yarn/cache/local-pkg-npm-0.4.0-c31827f33b-46964cea4b.zip/node_modules/local-pkg/)

I believe that this package needs to support basedir (similar to resolve), and set the paths option of require.resolve:

local-pkg/index.mjs

Lines 51 to 65 in fc9d06c

function resolvePackage(name, options = {}) {
try {
return require.resolve(`${name}/package.json`, options)
}
catch {
}
try {
return require.resolve(name, options)
}
catch (e) {
if (e.code !== 'MODULE_NOT_FOUND')
console.error(e)
return false
}
}

Yes this is still an issue. Is there an easy fix for this?

This also happens with pnpm: vitest-dev/vitest#3112.