unjs / mlly

🤝 Common ECMAScript module utils
MIT License
471 stars 36 forks source link

Dependency Conflicts in Monorepo: Errors Retrieving Dependencies #259

Closed wkeylin closed 5 months ago

wkeylin commented 5 months ago

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.

├── 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)

Additional context

No response

Logs

No response

wkeylin commented 5 months ago

158 closed