{"record":{"id":"dc338f637ea6377b","repo":"jackwener/OpenCLI","slug":"could-not-find-opencli-entrypoint-under-projectr","errorCode":null,"errorMessage":"Could not find opencli entrypoint under ${projectRoot}. Expected built entry from package.json or src/main.ts.","messagePattern":"Could not find opencli entrypoint under (.+?)\\. Expected built entry from package\\.json or src/main\\.ts\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli.ts","lineNumber":3737,"sourceCode":"} = {}): BrowserVerifyInvocation {\n  const platform = opts.platform ?? process.platform;\n  const fileExists = opts.fileExists ?? fs.existsSync;\n  const readFile = opts.readFile ?? ((filePath: string) => fs.readFileSync(filePath, 'utf-8'));\n  const projectRoot = opts.projectRoot ?? findPackageRoot(CLI_FILE, fileExists);\n\n  for (const builtEntry of getBuiltEntryCandidates(projectRoot, readFile)) {\n    if (fileExists(builtEntry)) {\n      return {\n        binary: process.execPath,\n        args: [builtEntry],\n        cwd: projectRoot,\n      };\n    }\n  }\n\n  const sourceEntry = path.join(projectRoot, 'src', 'main.ts');\n  if (!fileExists(sourceEntry)) {\n    throw new Error(`Could not find opencli entrypoint under ${projectRoot}. Expected built entry from package.json or src/main.ts.`);\n  }\n\n  const localTsxBin = path.join(projectRoot, 'node_modules', '.bin', platform === 'win32' ? 'tsx.cmd' : 'tsx');\n  if (fileExists(localTsxBin)) {\n    return {\n      binary: localTsxBin,\n      args: [sourceEntry],\n      cwd: projectRoot,\n      ...(platform === 'win32' ? { shell: true } : {}),\n    };\n  }\n\n  return {\n    binary: platform === 'win32' ? 'npx.cmd' : 'npx',\n    args: ['tsx', sourceEntry],\n    cwd: projectRoot,\n    ...(platform === 'win32' ? { shell: true } : {}),\n  };","sourceCodeStart":3719,"sourceCodeEnd":3755,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/src/cli.ts#L3719-L3755","documentation":"opencli failed to locate its own entrypoint script when resolving how to launch the CLI for a project. It looks for a built entry declared in package.json (bin/main) and falls back to src/main.ts; if neither exists under the resolved projectRoot, it throws. This is a project-structure/setup error, not a runtime logic bug.","triggerScenarios":"Running an opencli command in a directory (or against a projectRoot) that has no src/main.ts and no package.json entry pointing at a built entrypoint; running from a parent/child directory so projectRoot resolves to the wrong folder; a monorepo where main.ts lives in a package subdirectory.","commonSituations":"Cloning a repo and running the CLI before building; invoking opencli from the wrong working directory; renaming or moving main.ts without updating package.json; fresh checkout missing generated/built files.","solutions":["Run the command from the project root that actually contains src/main.ts (or the built entry).","Build the project so the entrypoint declared in package.json exists.","Verify package.json declares the correct main/bin entrypoint path.","Create or restore src/main.ts if it was renamed or deleted."],"exampleFix":"// before (package.json, no entry declared)\n{\n  \"name\": \"my-cli\"\n}\n// after\n{\n  \"name\": \"my-cli\",\n  \"main\": \"dist/main.js\",\n  \"bin\": { \"opencli\": \"dist/main.js\" }\n}","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nimport path from 'node:path';\nconst projectRoot = process.cwd();\nconst hasBuiltEntry = (() => {\n  const pkg = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));\n  return Boolean(pkg.main || pkg.bin);\n})();\nif (!hasBuiltEntry && !fs.existsSync(path.join(projectRoot, 'src', 'main.ts'))) {\n  throw new Error(`No opencli entrypoint under ${projectRoot}; build the project or add src/main.ts`);\n}","typeGuard":"function hasEntrypoint(root: string): boolean {\n  return fs.existsSync(path.join(root, 'src', 'main.ts')) || fs.existsSync(path.join(root, 'package.json'));\n}","tryCatchPattern":"try {\n  await opencli.run(args);\n} catch (e) {\n  if (e.message.includes('Could not find opencli entrypoint')) {\n    console.error('Run from the project root and build first: npm run build');\n    process.exitCode = 1;\n  } else throw e;\n}","preventionTips":["Always run opencli from the directory containing src/main.ts or a valid package.json entry.","Build (npm run build) after cloning before invoking CLI commands.","Keep package.json main/bin in sync when moving or renaming the entry file."],"tags":["cli","entrypoint","project-setup"],"backgroundTag":"missing-entrypoint","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}