{"record":{"id":"c1157db3b4b283d4","repo":"nocobase/nocobase","slug":"couldn-t-find-a-nocobase-source-project-from-cwd","errorCode":null,"errorMessage":"Couldn't find a NocoBase source project from --cwd: ${fallback}","messagePattern":"Couldn't find a NocoBase source project from --cwd: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/cli/src/lib/run-npm.ts","lineNumber":174,"sourceCode":"}\n\nexport function resolveProjectCwd(cwd?: string): string {\n  const normalizedCwd = typeof cwd === 'string' && cwd.trim() === '' ? undefined : cwd;\n  const fallback = resolveCwd(normalizedCwd);\n  const hasExplicitInput = normalizedCwd !== undefined;\n  if (hasExplicitInput && !pathExists(fallback)) {\n    throw new Error(`The specified --cwd does not exist: ${fallback}`);\n  }\n  if (hasExplicitInput && !isDirectory(fallback)) {\n    throw new Error(`The specified --cwd is not a directory: ${fallback}`);\n  }\n  let current = hasExplicitInput ? fallback : process.cwd();\n\n  while (!hasLocalNocoBaseBinary(current)) {\n    const parent = path.dirname(current);\n    if (parent === current) {\n      if (hasExplicitInput) {\n        throw new Error(`Couldn't find a NocoBase source project from --cwd: ${fallback}`);\n      }\n      return fallback;\n    }\n    current = parent;\n  }\n\n  return current;\n}\n\nexport async function run(name: string, args: string[], options?: RunProcessOptions): Promise<void> {\n  const cwd = resolveCwd(options?.cwd);\n  const label = options?.errorName ?? name;\n  const command = await resolveCommandName(name);\n  const stdio: StdioOptions = shouldTeeInheritedOutput(options)\n    ? ['inherit', 'pipe', 'pipe']\n    : (options?.stdio ?? 'inherit');\n  return await new Promise((resolve, reject) => {\n    const child = spawn(command, [...args], {","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/nocobase/nocobase/blob/fa42722fefe44265490dff2c27d79e2882bce4fa/packages/core/cli/src/lib/run-npm.ts#L156-L192","documentation":"After the existence/directory checks, resolveProjectCwd walks up parent directories looking for a local NocoBase binary (node_modules/.bin/nocobase-v1). If the filesystem root is reached without finding one AND --cwd was explicitly provided, this error is thrown. It means the given directory is not inside a NocoBase source project with installed dependencies.","triggerScenarios":"`nocobase <cmd> --cwd ~/some-random-dir` where no ancestor contains node_modules/.bin/nocobase-v1 — e.g. dependencies not installed (no yarn install), a non-NocoBase project, or a project whose nocobase-v1 binary name differs.","commonSituations":"Freshly cloned repo where `yarn install` was never run; running from an empty scratch directory; NocoBase installed globally rather than as a local source dependency; renamed node_modules via workspaces misconfiguration.","solutions":["Run `yarn install` (or npm install) in the target project so node_modules/.bin/nocobase-v1 exists.","Point --cwd at the actual NocoBase source root (the repo containing packages/ and node_modules).","Verify the marker file exists: ls <project>/node_modules/.bin/nocobase-v1.","If you are not in a source project, run the command from a location where the default (process.cwd) fallback is acceptable."],"exampleFix":"# before\ncd ~/empty-dir && nocobase dev --cwd ~/empty-dir   # Error: Couldn't find a NocoBase source project\n# after\ncd ~/nocobase && yarn install && nocobase dev --cwd ~/nocobase","handlingStrategy":"validation","validationCode":"import fs from 'fs';\nfunction hasNocoBaseBinary(dir: string): boolean {\n  return fs.existsSync(path.join(dir, 'node_modules', '.bin', 'nocobase-v1'));\n}\nif (!hasNocoBaseBinary(projectDir) && !walkUpHas(projectDir)) {\n  throw new Error(`Run yarn install in the NocoBase project; no nocobase-v1 binary found from ${projectDir}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await nocobaseCommand({ cwd: projectDir });\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"Couldn't find a NocoBase source project\")) {\n    console.error('Install dependencies (yarn install) in a NocoBase source checkout, or point --cwd at it.');\n  } else throw err;\n}","preventionTips":["Always run yarn install after cloning a NocoBase source repo.","Point --cwd at the repo root containing node_modules/.bin/nocobase-v1.","Verify the marker binary exists before scripting around the CLI.","Use the globally installed CLI for non-source deployments instead of --cwd."],"tags":["cli","filesystem","project-setup","dependencies"],"backgroundTag":"project-root-not-found","analyzedSha":"fa42722fefe44265490dff2c27d79e2882bce4fa","analyzedAt":"2026-09-01T00:54:31.202Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}