{"record":{"id":"38e0963193835993","repo":"can1357/oh-my-pi","slug":"share-script-must-export-a-default-function","errorCode":null,"errorMessage":"share script must export a default function","messagePattern":"share script must export a default function","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/export/custom-share.ts","lineNumber":57,"sourceCode":"\n\treturn null;\n}\n\n/**\n * Load the custom share script if it exists.\n */\nexport async function loadCustomShare(): Promise<LoadedCustomShare | null> {\n\tconst scriptPath = getCustomSharePath();\n\tif (!scriptPath) {\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst module = await import(scriptPath);\n\t\tconst fn = module.default;\n\n\t\tif (typeof fn !== \"function\") {\n\t\t\tthrow new Error(\"share script must export a default function\");\n\t\t}\n\n\t\treturn { path: scriptPath, fn };\n\t} catch (err) {\n\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\tthrow new Error(`Failed to load share script: ${message}`);\n\t}\n}\n","sourceCodeStart":39,"sourceCodeEnd":66,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/export/custom-share.ts#L39-L66","documentation":"loadCustomShare dynamically imports the user's share script (e.g. ~/.omp/agent/share.ts). The module's default export must be a function (CustomShareFn); if module.default is missing or not callable, this error is thrown and then wrapped by the catch into 'Failed to load share script: ...'. It is a contract check on the script's shape, not an import failure.","triggerScenarios":"Running /share (via handleShareCommand) while ~/.omp/agent/share.ts|.js|.mjs exists but exports nothing as default, exports a non-function default (object, string, class), or uses `export =` style (CommonJS) semantics.","commonSituations":"User copied a named-export example instead of default export; wrote `module.exports = {...}` in a .js script; refactored the script and renamed the default export; TypeScript compiled output losing the default export.","solutions":["Add a default function export: `export default async function share(htmlPath: string) {...}`.","If using CommonJS in .js, use `module.exports.default = share` or switch to ESM syntax.","Verify the file type (.ts/.js/.mjs) parses under the runtime's module system — .mjs forces ESM.","Check the wrapped error message ('Failed to load share script: ...') to confirm it's this contract error vs a syntax error."],"exampleFix":"// before (share.ts)\nexport async function share(htmlPath: string) { ... }\n// after\nexport default async function share(htmlPath: string) { ... }","handlingStrategy":"validation","validationCode":"const mod = await import(scriptPath);\nif (typeof mod.default !== \"function\") {\n  console.error(`${scriptPath} must 'export default' an async function`);\n  process.exit(1);\n}","typeGuard":"function isCustomShareFn(v: unknown): v is (htmlPath: string) => Promise<unknown> {\n  return typeof v === \"function\";\n}","tryCatchPattern":"try {\n  const share = await loadCustomShare();\n} catch (err) {\n  console.error((err as Error).message);\n  console.error(\"Fix or remove ~/.omp/agent/share.ts; falling back to Gist sharing.\");\n}","preventionTips":["Always use `export default` in the share script — named exports are ignored.","Keep the exported function async and matching (htmlPath: string) => Promise<CustomShareResult | string | undefined>.","Remove or rename the script when not in use so it isn't picked up by the share.ts/.js/.mjs candidate scan."],"tags":["module","export","configuration","dynamic-import"],"backgroundTag":"missing-default-export","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}