nx icon indicating copy to clipboard operation
nx copied to clipboard

unable to run script when cwd is a yarn berry workspace

Open ZeekoZhu opened this issue 3 years ago • 0 comments
trafficstars

Reproduce

  1. create a workspace project with yarn berry
  2. cd into a workspace, execute nx run-script executor

Expect

run-script should use yarn as the package manager and use yarn run to execute npm scripts

Actual

it use npm as the package manager and unable to resolve the bin package

❯ nx build

> nx run icons:build


> [email protected] build /home/xxxx/WebstormProjects/xxxxx/packages/icons
> run-s clean:dist build:src

sh: line 1: run-s: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! [email protected] build: `run-s clean:dist build:src`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/xxxxx/.npm/_logs/2022-08-08T15_00_30_985Z-debug.log

Why

  1. yarn berry only creates yarn.lock in the root project, it doesn't create a lock file for each workspace project
  2. when nx detecting the PM, it only checks the lock file in CWD

https://github.com/nrwl/nx/blob/8bc99407aac128102a7ebc7ee73824c78d9e4aa0/packages/nx/src/executors/run-script/run-script.impl.ts#L15

https://github.com/nrwl/nx/blob/8bc99407aac128102a7ebc7ee73824c78d9e4aa0/packages/nx/src/utils/package-manager.ts#L30-L36

ZeekoZhu avatar Aug 08 '22 15:08 ZeekoZhu

Yarn 2+ support is tracked in https://github.com/nrwl/nx/issues/2386

AgentEnder avatar Aug 12 '22 21:08 AgentEnder