{"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":null,"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/f9245100cf0d31d96628804ead485f6bf226e55a/packages/turbo-gen/src/generators/copy.ts#L24-L60","documentation":"The turbo-gen copy generator copies an external example into your monorepo as a single new workspace. After the copy, it validates that the result is one package, not another monorepo root. It throws this Error when the copied package.json declares a workspaces field, which marks the example as a monorepo root. The catch block logs the message, deletes the copied directory, and aborts.","triggerScenarios":"You run turbo gen with a copy source that is itself a monorepo. createProject copies it in, fs.readJSON loads its package.json, packageJson.workspaces is truthy, and the guard throws. The generator rolls back by removing the destination directory.","commonSituations":"Pointing turbo gen at an official or community example that is a full monorepo rather than a single app. Copying a starter that recently restructured into workspaces. examplePath selecting the root of an example instead of a single package inside it.","solutions":["Choose a single-package example as the copy source","If the example is a monorepo, point the example path at one package directory inside it instead of the repository root","If you own the source, remove the workspaces field or publish a single-package variant"],"exampleFix":"# before: copying a monorepo example root\nnpm exec turbo gen -- --copy https://github.com/example/monorepo-root\n# after: copy one package from inside it\nnpm exec turbo gen -- --copy https://github.com/example/monorepo-root --example-path apps/web","handlingStrategy":"validation","validationCode":"// inspect a copy source for monorepo markers before running turbo gen\nimport fs from \"node:fs\";\n\nfunction isSinglePackageExample(dir: string): boolean {\n  const pkg = JSON.parse(fs.readFileSync(`${dir}/package.json`, \"utf8\"));\n  const hasWorkspaces = Boolean(pkg.workspaces);\n  const hasPnpmWorkspace = fs.existsSync(`${dir}/pnpm-workspace.yaml`);\n  return !hasWorkspaces && !hasPnpmWorkspace;\n}","typeGuard":"function isWorkspaceRootManifest(pkg: { workspaces?: unknown }): boolean {\n  return Boolean(pkg.workspaces);\n}","tryCatchPattern":null,"preventionTips":["Copy from single-package examples only, or target a package directory with example path","Clone the example locally and inspect its package.json before referencing it","Watch upstream examples for restructuring into monorepos"],"tags":["turbo-gen","generator","copy","monorepo","workspace","validation"],"backgroundTag":"template-validation-failed","analyzedSha":"f9245100cf0d31d96628804ead485f6bf226e55a","analyzedAt":"2026-08-17T10:46:15.696Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}