Skip to content

[GENERAL QUERY] Managing Dependencies in a Yarn Berry Monorepo when running scripts from packagesΒ #6474

@karthickshanmugam0689

Description

@karthickshanmugam0689

We are currently in the process of migrating our private monorepo from yarn classic to yarn modern, specifically yarn pnp, in order to take advantage of the latest yarn features. Although this query may have been addressed in the past, I am seeking further clarification on dependency management with yarn berry.
Suppose we have a monorepo with the following structure, which has been migrated to yarn modern but not yet to pnp:

β”œβ”€β”€ package.json # Includes webpack as a dependency
β”œβ”€β”€ apps                    
β”‚   β”œβ”€β”€ app1
β”‚   β”‚   └── package.json # Contains a "build" script that runs "webpack mode --production"     
β”‚   β”œβ”€β”€ app2   
β”‚   β”‚   └── package.json       
β”‚   └── app3
β”‚       └── package.json                
└── libs
    └── core
        └── package.json 

In this case, when running the build script from app1, the error "command not found: webpack" is displayed. After researching online, I discovered that this can be resolved by adding "run -T" to the build command, resulting in "run -T webpack mode --production". However, this solution would need to be added not only to commands using webpack, but to all commands that reference dependencies from the root level (e.g. tsc). Given that there are around 220 packages in this monorepo, this solution would be cumbersome.
Is there an alternative solution to this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions