{"record":{"id":"96fea68ddd9205cd","repo":"vercel/turborepo","slug":"new-workspace-root-detected-unexpected-workspac","errorCode":null,"errorMessage":"New workspace root detected - unexpected 'workspaces' field in package.json","messagePattern":"New workspace root detected - unexpected 'workspaces' field in package\\.json","errorType":"console","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/turbo-gen/src/generators/copy.ts","lineNumber":42,"sourceCode":"  if (opts.copy.type === \"external\") {\n    logger.log();\n    logger.warn(\"Some manual modifications may be required.\");\n    logger.dimmed(\n      `This ${type} may require local dependencies or a different package manager than what is available in this repo`\n    );\n    await createProject({\n      appPath: location.absolute,\n      example: opts.copy.source,\n      examplePath: opts.examplePath\n    });\n\n    try {\n      if (fs.existsSync(newPackageJsonPath)) {\n        const packageJson = (await fs.readJSON(\n          newPackageJsonPath\n        )) as PackageJson;\n        if (packageJson.workspaces) {\n          throw new Error(\n            \"New workspace root detected - unexpected 'workspaces' field in package.json\"\n          );\n        }\n      } else {\n        throw new Error(\"New workspace is missing a package.json file\");\n      }\n\n      if (fs.existsSync(path.join(location.absolute, \"pnpm-workspace.yaml\"))) {\n        throw new Error(\n          \"New workspace root detected - unexpected pnpm-workspace.yaml\"\n        );\n      }\n    } catch (err) {\n      let message = \"UNKNOWN_ERROR\";\n      if (err instanceof Error) {\n        message = err.message;\n      }\n      logger.error(message);","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/vercel/turborepo/blob/9f94a7d215b3881942527dd526afa3fc650869d5/packages/turbo-gen/src/generators/copy.ts#L24-L60","documentation":"`turbo gen --copy` copies an existing package into the monorepo as a new workspace, then runs post-copy guards: the copied package.json must NOT have a `workspaces` field, because that would mean you copied a monorepo root and are trying to nest one workspace system inside another. On failure the error is logged and the copied directory is rolled back (recursively removed).","triggerScenarios":"Passing --copy (or opts.copy.source) a directory whose package.json contains a `workspaces` array — i.e. an npm/Yarn workspaces monorepo root rather than a single package.","commonSituations":"Trying to absorb a standalone app that was itself a monorepo; copying a repository root when the actual app lives in a sub-package; leftover `workspaces` fields in a single-package repo from an earlier monorepo experiment.","solutions":["Point --copy at the specific workspace package (the sub-directory whose package.json has no `workspaces` field), not the monorepo root","If the source is genuinely a single app with a stale `workspaces` field, delete that field from its package.json and re-run","For true monorepo-to-monorepo merges, copy each workspace package individually with --copy, or move files manually and register them in the root workspaces globs"],"exampleFix":"# before\nturbo gen --copy ~/src/my-monorepo        # root has workspaces: [\"apps/*\"]\n# after\nturbo gen --copy ~/src/my-monorepo/apps/web","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\n\nfunction isSinglePackageSource(dir: string): boolean {\n  const pkgPath = `${dir}/package.json`;\n  if (!fs.existsSync(pkgPath)) return false;\n  const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));\n  return !pkg.workspaces; // a workspaces field means it is a monorepo root\n}","typeGuard":"function isMonorepoRoot(pkgJson: { workspaces?: unknown }): boolean {\n  return Array.isArray(pkgJson.workspaces) || typeof pkgJson.workspaces === 'object';\n}","tryCatchPattern":null,"preventionTips":["Always --copy a leaf workspace package, never a repository root","Check the source's package.json for a `workspaces` field before invoking turbo gen --copy","Remember failure rolls back the copy — fix the source and re-run cleanly rather than repairing half-copied state"],"tags":["turbo-gen","workspace","monorepo","copy","package-json"],"backgroundTag":"workspace-config-conflict","analyzedSha":"9f94a7d215b3881942527dd526afa3fc650869d5","analyzedAt":"2026-08-16T19:47:29.531Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}