can1357/oh-my-pi · error · Error
share script must export a default function
Error message
share script must export a default function
What it means
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.
Source
Thrown at packages/coding-agent/src/export/custom-share.ts:57
return null;
}
/**
* Load the custom share script if it exists.
*/
export async function loadCustomShare(): Promise<LoadedCustomShare | null> {
const scriptPath = getCustomSharePath();
if (!scriptPath) {
return null;
}
try {
const module = await import(scriptPath);
const fn = module.default;
if (typeof fn !== "function") {
throw new Error("share script must export a default function");
}
return { path: scriptPath, fn };
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
throw new Error(`Failed to load share script: ${message}`);
}
}
View on GitHub (pinned to 9690622007)
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.
Example fix
// before (share.ts)
export async function share(htmlPath: string) { ... }
// after
export default async function share(htmlPath: string) { ... } Defensive patterns
Strategy: validation
Validate before calling
const mod = await import(scriptPath);
if (typeof mod.default !== "function") {
console.error(`${scriptPath} must 'export default' an async function`);
process.exit(1);
} Type guard
function isCustomShareFn(v: unknown): v is (htmlPath: string) => Promise<unknown> {
return typeof v === "function";
} Try / catch
try {
const share = await loadCustomShare();
} catch (err) {
console.error((err as Error).message);
console.error("Fix or remove ~/.omp/agent/share.ts; falling back to Gist sharing.");
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to load share script: ${message}
- No model configured
- Azure OpenAI base URL is required. Set AZURE_OPENAI_BASE_URL
- Cannot register custom API "${api}": built-in API names are
- Unable to read OMP_AUTH_BROKER_ACCOUNT_POOL_FILE at ${filePa
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/38e0963193835993.
Report an issue: GitHub.