hermes - 💡(How to fix) Fix TUI bundled entry.js fails on Node.js v18: Cannot use import statement outside a module

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

SyntaxError: Cannot use import statement outside a module at internalCompileFunction (node:internal/vm:73:18) ... at node:internal/main/run_main_module:28:49

Root Cause

In hermes_cli/main.py::_make_tui_argv(), two code paths construct the node argv without --input-type=module:

Line ~1380 (external dir case):

return [node, "--expose-gc", str(p / "dist" / "entry.js")], p

Line ~1386 (bundled wheel case):

return [node, "--expose-gc", str(bundled)], bundled.parent

Both should include "--input-type=module" to tell Node.js to treat the .js file as an ES module.

Fix Action

Workaround

Users can manually add --input-type=module or create a package.json in their tui_dist directory:

echo '{"type":"module"}' > $(python -c "import hermes_cli; import os; print(os.path.dirname(hermes_cli.__file__))")/tui_dist/package.json

Code Example

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    ...
    at node:internal/main/run_main_module:28:49

---

return [node, "--expose-gc", str(p / "dist" / "entry.js")], p

---

return [node, "--expose-gc", str(bundled)], bundled.parent

---

- return [node, "--expose-gc", str(p / "dist" / "entry.js")], p
+ return [node, "--expose-gc", "--input-type=module", str(p / "dist" / "entry.js")], p

- return [node, "--expose-gc", str(bundled)], bundled.parent
+ return [node, "--expose-gc", "--input-type=module", str(bundled)], bundled.parent

---

echo '{"type":"module"}' > $(python -c "import hermes_cli; import os; print(os.path.dirname(hermes_cli.__file__))")/tui_dist/package.json
RAW_BUFFERClick to expand / collapse

Bug Description

When running hermes --tui with pip-installed Hermes (wheel distribution), the TUI crashes immediately:

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    ...
    at node:internal/main/run_main_module:28:49

This happens because tui_dist/entry.js uses ES Module syntax (import { createRequire }...) but is invoked without telling Node.js it's an ESM file. There's no package.json with "type": "module" in the tui_dist directory, so Node.js treats .js as CommonJS.

Reproduction Steps

  1. Install Hermes via pip: pip install hermes-agent
  2. Run: hermes --tui
  3. Observe SyntaxError crash

Affected: WSL Ubuntu 24.04, Node.js v18.19.1, Hermes Agent v0.15.2

Root Cause

In hermes_cli/main.py::_make_tui_argv(), two code paths construct the node argv without --input-type=module:

Line ~1380 (external dir case):

return [node, "--expose-gc", str(p / "dist" / "entry.js")], p

Line ~1386 (bundled wheel case):

return [node, "--expose-gc", str(bundled)], bundled.parent

Both should include "--input-type=module" to tell Node.js to treat the .js file as an ES module.

Proposed Fix

Add "--input-type=module" to both node argv lists:

- return [node, "--expose-gc", str(p / "dist" / "entry.js")], p
+ return [node, "--expose-gc", "--input-type=module", str(p / "dist" / "entry.js")], p

- return [node, "--expose-gc", str(bundled)], bundled.parent
+ return [node, "--expose-gc", "--input-type=module", str(bundled)], bundled.parent

Alternatively, ship a package.json with {"type": "module"} alongside entry.js in the wheel bundle. The flag approach is preferred since it works regardless of whether a package.json exists.

Workaround

Users can manually add --input-type=module or create a package.json in their tui_dist directory:

echo '{"type":"module"}' > $(python -c "import hermes_cli; import os; print(os.path.dirname(hermes_cli.__file__))")/tui_dist/package.json

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING