{"record":{"id":"661b8d6cfa19cfa8","repo":"neoclide/coc.nvim","slug":"main-file-main-not-found-you-may-need-to-build","errorCode":null,"errorMessage":"main file ${main} not found, you may need to build the project.","messagePattern":"main file (.+?) not found, you may need to build the project\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/extension/stat.ts","lineNumber":285,"sourceCode":"function getEntryFile(main: string | undefined): string {\n  if (!main) return 'index.js'\n  if (!main.endsWith('.js')) return main + '.js'\n  return main\n}\n\nexport async function loadGlobalJsonAsync(folder: string, version: string): Promise<ExtensionJson> {\n  let jsonFile = path.join(folder, 'package.json')\n  let content = await readFile(jsonFile, 'utf8')\n  let packageJSON = JSON.parse(content) as ExtensionJson\n  let { engines } = packageJSON\n  let main = getEntryFile(packageJSON.main)\n  if (!engines || (typeof engines.coc !== 'string' && typeof engines.vscode !== 'string')) throw new Error('Invalid engines field')\n  let keys = Object.keys(engines)\n  if (keys.includes('coc') && !semver.satisfies(version, engines['coc'].replace(/^\\^/, '>='))) {\n    throw new Error(`coc.nvim version not match, required ${engines['coc']}`)\n  }\n  if (!engines.vscode && !fs.existsSync(path.join(folder, main))) {\n    throw new Error(`main file ${main} not found, you may need to build the project.`)\n  }\n  return packageJSON\n}\n\nexport function loadExtensionJson(folder: string, version: string, errors: string[]): ExtensionJson | undefined {\n  let jsonFile = path.join(folder, 'package.json')\n  if (!fs.existsSync(jsonFile)) {\n    errors.push(`package.json not found in ${folder}`)\n    return undefined\n  }\n  let packageJSON = loadJson(jsonFile) as ExtensionJson\n  let { name, engines } = packageJSON\n  let main = getEntryFile(packageJSON.main)\n  if (!name) errors.push(`can't find name in package.json`)\n  if (!engines || !objectLiteral(engines)) {\n    errors.push(`invalid engines in ${jsonFile}`)\n  }\n  if (engines && !engines.vscode && !fs.existsSync(path.join(folder, main))) {","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/extension/stat.ts#L267-L303","documentation":"Thrown by loadGlobalJsonAsync when the extension has no engines.vscode entry and its declared main entry file does not exist on disk. This usually means the extension source has not been compiled/built.","triggerScenarios":"Loading an extension folder where package.json main (e.g. lib/index.js) is missing because the project was never built, was partially installed, or main field is wrong.","commonSituations":"Cloning an extension from source and loading it without running npm install/build; missing dist/lib after CI packaging; TypeScript extension without compiled output.","solutions":["Build the extension (npm install && npm run build / yarn build) to produce the main file","Verify the `main` field in package.json matches the actual output file","Reinstall the extension from a published release"],"exampleFix":"// before\nls my-ext # only src/, no lib/\n// after\ncd my-ext && npm install && npm run build # creates lib/index.js referenced by main","handlingStrategy":"validation","validationCode":"const pkg = JSON.parse(fs.readFileSync(path.join(folder, 'package.json'), 'utf8'));\nif (!pkg.engines?.vscode) {\n  const main = pkg.main || 'index.js';\n  if (!fs.existsSync(path.join(folder, main))) {\n    console.error(`main file ${main} missing - build required`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await coc.extensions.load(folder, true);\n} catch (e) {\n  if (String(e.message).includes('main file') && String(e.message).includes('not found')) {\n    console.error(`Build the extension in ${folder} (npm install && npm run build)`);\n  } else throw e;\n}","preventionTips":["Run npm install && npm run build after cloning from source","Verify main file exists before packaging/loading","Use published releases for production setups"],"tags":["extension","missing-file","build"],"backgroundTag":"missing-build-output","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}