In a monorepo setup, if both the subdirectory and the parent directory have the same dependency, retrieving the dependency from package.json can cause errors.
├── node_modules
│ └── vue -> .pnpm/vue@2.7.16/node_modules/vue #vue@2.7 in the root directory
├── package.json
├── packages
│ └── test
│ ├── index.js
│ ├── node_modules
│ │ └── vue -> ../../../node_modules/.pnpm/vue@3.2.47/node_modules/vue #vue@3 in the subdirectory
│ └── package.json
├── pnpm-lock.yaml
└── pnpm-workspace.yaml
// packages/test/index.js
import { resolvePathSync } from 'mlly'
import process from 'node:process'
console.log('current dir', process.cwd())
const url = resolvePathSync('vue/package.json', {
url: process.cwd()
})
console.log('resolved url', url) // The output URL points to the dependency path in the parent directory(vue@2.7)
Environment
node22
Reproduction
https://github.com/wkeylin/mlly-demo
Describe the bug
In a monorepo setup, if both the subdirectory and the parent directory have the same dependency, retrieving the dependency from package.json can cause errors.
Additional context
No response
Logs
No response