vercel/turborepo · error
New workspace is missing a package.json file
Error message
New workspace is missing a package.json file
What it means
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.
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
Example fix
# before: path without a package.json npm exec turbo gen -- --copy https://github.com/org/repo --example-path docs # after: path that contains the package npm exec turbo gen -- --copy https://github.com/org/repo --example-path apps/demo
Defensive patterns
Strategy: validation
Validate before calling
import fs from "node:fs";
// confirm the copy target contains a package.json before running turbo gen
if (!fs.existsSync(path.join(sourceDir, "package.json"))) {
throw new Error(`${sourceDir} has no package.json; pick a package directory`);
} Type guard
function isPackageDirectory(dir: string): boolean {
return fs.existsSync(`${dir}/package.json`);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- New workspace root detected - unexpected pnpm-workspace.yaml
- New workspace root detected - unexpected 'workspaces' field…
- plop_error_running_generator
- plop_generator_not_found
- Workspace " " not found
AI-assisted analysis of vercel/turborepo@f9245100cf (2026-08-17).
Data as JSON: /api/errors/749a694d9efdde8a.
Report an issue: GitHub.
Appendix: source
Thrown at packages/turbo-gen/src/generators/copy.ts:47
);
await createProject({
appPath: location.absolute,
example: opts.copy.source,
examplePath: opts.examplePath
});
try {
if (fs.existsSync(newPackageJsonPath)) {
const packageJson = (await fs.readJSON(
newPackageJsonPath
)) as PackageJson;
if (packageJson.workspaces) {
throw new Error(
"New workspace root detected - unexpected 'workspaces' field in package.json"
);
}
} else {
throw new Error("New workspace is missing a package.json file");
}
if (fs.existsSync(path.join(location.absolute, "pnpm-workspace.yaml"))) {
throw new Error(
"New workspace root detected - unexpected pnpm-workspace.yaml"
);
}
} catch (err) {
let message = "UNKNOWN_ERROR";
if (err instanceof Error) {
message = err.message;
}
logger.error(message);
// rollback changes
await fs.rm(location.absolute, { recursive: true, force: true });
return;
}View on GitHub (pinned to f9245100cf)