{"record":{"id":"c41f09d0645e48a7","repo":"apify/crawlee","slug":"the-project-name-cannot-be-empty-string","errorCode":null,"errorMessage":"The project name cannot be empty string.","messagePattern":"The project name cannot be empty string\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/CreateProjectCommand.ts","lineNumber":21,"sourceCode":"import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { get } from 'node:https';\nimport { dirname, join, resolve } from 'node:path';\nimport { setTimeout } from 'node:timers/promises';\n\nimport type { Template } from '@crawlee/templates';\nimport { fetchManifest } from '@crawlee/templates';\nimport { input, select } from '@inquirer/prompts';\nimport colors from 'ansi-colors';\nimport type { ArgumentsCamelCase, Argv, CommandModule } from 'yargs';\n\ninterface CreateProjectArgs {\n    projectName?: string;\n    template?: string;\n}\n\nfunction validateProjectName(name: string) {\n    if (name.length === 0) {\n        throw new Error('The project name cannot be empty string.');\n    }\n}\n\nasync function rewrite(path: string, replacer: (from: string) => string) {\n    try {\n        const file = await readFile(path, 'utf8');\n        const replaced = replacer(file);\n        await writeFile(path, replaced);\n    } catch {\n        // not found\n    }\n}\n\nasync function withRetries<F extends (...args: unknown[]) => unknown>(\n    func: F,\n    retries: number,\n    label: string,\n): Promise<Awaited<ReturnType<F>>> {","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/apify/crawlee/blob/dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c/packages/cli/src/commands/CreateProjectCommand.ts#L3-L39","documentation":"The Crawlee CLI `create` command validates the project name before scaffolding and rejects an empty string, since templates need a non-empty name for the directory and package name substitution.","triggerScenarios":"Running the create command with a name that resolves to an empty string, e.g. `npx crawlee create \"\"` or passing a flag/argument that ends up empty after quoting/variable expansion.","commonSituations":"Shell scripts using unquoted/empty environment variables (`PROJECT_NAME=\"\"`), CI pipelines interpolating an unset variable, accidental extra whitespace handling in wrappers.","solutions":["Pass a non-empty project name to the create command.","In scripts, validate `${PROJECT_NAME}` is non-empty before invoking the CLI.","Omit the name argument entirely to let the CLI prompt interactively."],"exampleFix":"# before\nnpx crawlee create \"$PROJECT_NAME\"\n# after\n[ -n \"$PROJECT_NAME\" ] || { echo 'PROJECT_NAME is empty'; exit 1; }\nnpx crawlee create \"$PROJECT_NAME\"","handlingStrategy":"validation","validationCode":"const name = process.argv[3] ?? '';\nif (name.trim().length === 0) { console.error('Project name must be non-empty'); process.exit(1); }","typeGuard":"function isValidProjectName(v: unknown): v is string { return typeof v === 'string' && v.trim().length > 0; }","tryCatchPattern":"try { await createProject({ projectName: name }); } catch (err) { if (err.message.includes('cannot be empty string')) { console.error('Supply a non-empty project name'); } else { throw err; } }","preventionTips":["Quote and default shell variables: \"${PROJECT_NAME:?PROJECT_NAME is required}\"","Validate CLI arguments in wrapper scripts before invoking the CLI","Check CI variables are set before running crawlee create"],"tags":["cli","validation","input-validation"],"backgroundTag":"invalid-input-validation","analyzedSha":"dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c","analyzedAt":"2026-08-30T22:22:28.328Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}