nodejs/node · error · Error

No workspaces found${msg}

Error message

No workspaces found${msg}

What it means

Thrown by getWorkspaces when, after applying any --workspace filters against the discovered workspace map (plus optional root), the result map is empty. With no filters the message is 'No workspaces found!' (no colon list); with filters it lists each as ' --workspace=<filter>'. The workspaces come from @npmcli/map-workspaces reading the root package.json `workspaces` field.

Source

Thrown at deps/npm/lib/utils/get-workspaces.js:48

      const relativeFilter = relative(path, filterArg)
      if (filterArg === workspaceName
        || resolve(relativeFrom, filterArg) === workspacePath
        || minimatch(relativePath, `${globify(relativeFilter)}/*`)
        || minimatch(relativePath, `${globify(filterArg)}/*`)
      ) {
        res.set(workspaceName, workspacePath)
      }
    }
  }

  if (!res.size) {
    let msg = '!'
    if (filters.length) {
      msg = `:\n ${filters.reduce(
        (acc, filterArg) => `${acc} --workspace=${filterArg}`, '')}`
    }

    throw new Error(`No workspaces found${msg}`)
  }

  return res
}

module.exports = getWorkspaces

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Verify the root package.json has a `workspaces` array/glob and that matching directories contain package.json files.
  2. List valid workspace names from your root package.json and correct the `--workspace` filter spelling/path.
  3. Drop the workspace flag if you did not mean to operate in workspace mode.

Example fix

// before
// package.json has "workspaces": ["packages/*"] but no packages/a dir
npm install --workspace=packge-a   // typo
// after
npm install --workspace=package-a
Defensive patterns

Strategy: validation

Validate before calling

const root = JSON.parse(await readFile('package.json', 'utf8'))
const wsMap = await mapWorkspaces({ cwd: process.cwd(), pkg: root })
for (const f of filters) {
  if (!wsMap.has(f)) {
    throw new Error(`--workspace=${f} matches no configured workspace; valid: ${[...wsMap.keys()].join(', ')}`)
  }
}

Type guard

const isValidWorkspaceFilter = (filters, wsMap) =>
  filters.every(f => wsMap.has(f))

Try / catch

try {
  await getWorkspaces(filters, opts)
} catch (err) {
  if (/No workspaces found/i.test(err.message)) {
    // log the available workspace names from package.json, then re-prompt
  } else { throw err }
}

Prevention

When it happens

Trigger: Any workspace-aware command (`-w`, `-ws`) when: (a) the root package.json has no `workspaces` field at all and no filter matches; (b) a filter name/path does not match any configured workspace; (c) the workspaces glob exists but the matched directories lack their own package.json.

Common situations: Typo in `--workspace` name; running in a non-monorepo; workspace globs out of sync with directory layout; renamed a workspace package but not the filter.

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/77bb4404e11f522f. Report an issue: GitHub.