{"record":{"id":"749a694d9efdde8a","repo":"vercel/turborepo","slug":"new-workspace-is-missing-a-package-json-file","errorCode":null,"errorMessage":"New workspace is missing a package.json file","messagePattern":"New workspace is missing a package\\.json file","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/turbo-gen/src/generators/copy.ts","lineNumber":47,"sourceCode":"    );\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);\n\n      // rollback changes\n      await fs.rm(location.absolute, { recursive: true, force: true });\n      return;\n    }","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/vercel/turborepo/blob/f9245100cf0d31d96628804ead485f6bf226e55a/packages/turbo-gen/src/generators/copy.ts#L29-L65","documentation":"The turbo-gen copy generator requires every new workspace to have a package.json. After copying an external example, it checks that the destination package.json exists. It throws this Error when the file is absent, then logs it and deletes the copied directory as a rollback.","triggerScenarios":"The copy source contains no package.json at its root. This happens when the example path points at a subfolder without one, at an empty repository, or at a repo whose layout changed. fs.existsSync(newPackageJsonPath) is false, so the else branch throws.","commonSituations":"examplePath points to a docs folder or asset directory instead of a package. The upstream example restructured and the old path no longer holds a package. The repository name in the copy URL is misspelled, so an empty tree is copied.","solutions":["Open the copy source and confirm which directory holds the package.json","Adjust the copy URL or example path so it targets that directory","If you own the source, add a valid package.json to the copied directory"],"exampleFix":"# before: path without a package.json\nnpm exec turbo gen -- --copy https://github.com/org/repo --example-path docs\n# after: path that contains the package\nnpm exec turbo gen -- --copy https://github.com/org/repo --example-path apps/demo","handlingStrategy":"validation","validationCode":"import fs from \"node:fs\";\n\n// confirm the copy target contains a package.json before running turbo gen\nif (!fs.existsSync(path.join(sourceDir, \"package.json\"))) {\n  throw new Error(`${sourceDir} has no package.json; pick a package directory`);\n}","typeGuard":"function isPackageDirectory(dir: string): boolean {\n  return fs.existsSync(`${dir}/package.json`);\n}","tryCatchPattern":null,"preventionTips":["Point example paths at directories that contain a package.json","Verify example repository structure after upstream releases","Prefer official single-app examples over ad-hoc repositories"],"tags":["turbo-gen","generator","copy","package-json","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"}