Search code examples
javascriptnode.jsmonorepopnpmpnpm-workspace

"Error: packages field is not an array when using pnpm-workspace.yaml in a monorepo setup"


I'm working with a PNPM monorepo setup, and everything was working fine when I was using pnpm.yaml, but after switching to pnpm-workspace.yaml, I’m encountering the following error:

ERROR  packages field is not an array
For help, run: pnpm help run

Here’s my current directory structure:

root-directory/
  ├── packages/
  │    └── main/
  │        ├── index.js
  │        └── package.json
  ├── package.json
  └── pnpm-workspace.yaml

Root package.json:

{
  "name": "@levelup/root",
  "version": "1.0.0",
  "scripts": {
    "main:start": "pnpm -F @levelup/main run start",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "packageManager": "pnpm@10.5.1"
}

pnpm-workspace.yaml:

packages:
  - "packages/**"


Solution

  • The error occurs because the packages field in your pnpm-workspace.yaml file is not formatted correctly. In YAML, lists should be properly indented and use a hyphen (-) for each item.

      packages:
        - "packages/**"
               
    

    Make sure there are no extra spaces or incorrect indentation.

      packages:
        - "packages/**"
    
    • Open pnpm-workspace.yaml and ensure the packages field is written correctly.
    • Save the file and run pnpm install again.