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

  1. Add a default function export: `export default async function share(htmlPath: string) {...}`.
  2. If using CommonJS in .js, use `module.exports.default = share` or switch to ESM syntax.
  3. Verify the file type (.ts/.js/.mjs) parses under the runtime's module system — .mjs forces ESM.
  4. 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

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


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/38e0963193835993. Report an issue: GitHub.