Skip to content

fix(examples): replace CommonJS require.main guard with ESM equivalent - #168

Draft
ling-senpeng13 wants to merge 1 commit into
mainfrom
fix/esm-main-guard-examples
Draft

fix(examples): replace CommonJS require.main guard with ESM equivalent#168
ling-senpeng13 wants to merge 1 commit into
mainfrom
fix/esm-main-guard-examples

Conversation

@ling-senpeng13

Copy link
Copy Markdown
Contributor

63-deploy.ts and 63d-serve-from-package.ts guard main() with if (require.main === module) so that 63c-run-by-name.ts / 63e-run-monitoring.ts can import their agents without triggering a run. But the examples execute as ES modules, where require doesn't exist — so both files crashed with ReferenceError: require is not defined on direct execution and on import, breaking all four examples.

Replaced with the ESM equivalent:

if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {

Verified against conductor-oss 3.32.0-rc18: all five 63-family examples complete — 63/63b/63d run directly, 63c and 63e import from the guarded files and execute exactly one agent run each (guard confirmed to block main() on import).

63-deploy.ts and 63d-serve-from-package.ts guarded main() with
'require.main === module', which throws ReferenceError in ES module
scope — crashing both on direct execution and, transitively, 63c and
63e which import agents from them. Replace with the import.meta.url
comparison so the guard keeps preventing main() from running on import.
@ling-senpeng13
ling-senpeng13 marked this pull request as ready for review August 17, 2026 23:35
@ling-senpeng13
ling-senpeng13 marked this pull request as draft August 18, 2026 00:25
@kowser-orkes

Copy link
Copy Markdown
Contributor

I have investigated

Delete followings

  • 63c-run-by-name.ts
  • 63e-run-monitoring.ts

For others

  • update readme
  • remove if guard for main invocation from other scripts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants