Force yarn install for Cloudflare pages builds

I’ve spelunked around Cloudflare’s docs and various forums, but can’t seem to find an answer elsewhere. I use yarn workspaces in a monorepo and my builds fail with the following error:

npm ERR! Unsupported URL Type "workspace:": workspace:*

I’ve specified my package manager as "packageManager": "[email protected]" in package.json and have set the NODE_VERSION and YARN_VERSION env variables (“16.15.1” and “3.2.1”, respectively) and Cloudflare still defaults to npm install instead of yarn. Yarn is available and works correctly in subsequent steps such as yarn build if I disable workspaces to get through the npm stage, but the build ultimately fails to find the files needed since the “workspace:*” links are essential for sharing internal packages.

Everything builds and compiles locally with my existing yarn setup, so there is likely a configuration step I’m missing or is incorrectly implemented, so any suggestions would be greatly appreciated.

I’m fairly certain it’ll only use yarn over npm install if you have a yarn.lock committed - do you have that?

@KianNH I do have yarn.lock committed, and coincidentally, your comment triggered something important that I didn’t know about Cloudflare’s deployments. Apparently, the presence of a yarn.lock file in is the implicit trigger to use yarn instead of NPM. I updated the root (leave it at the root of the project) and build output folder (prepend the /app/** path) variables, and everything now works as expected.

For future searchers in case it’s helpful. Locally, yarn is smart enough to trigger a root-level yarn install if executed from within a workspace subdirectory, and maintains a yarn.lock at the root of the project. In the Cloudflare build environment, setting the deployment root to something like /apps/... will default to NPM due to the lack of a yarn.lock within the sub folder.