Skip to content

fix(plugin): prevent raw .ts import crash when esbuild transpilation fails#503

Merged
jackwener merged 1 commit intojackwener:mainfrom
ByteYue:fix/ts-plugin-loading-500
Mar 27, 2026
Merged

fix(plugin): prevent raw .ts import crash when esbuild transpilation fails#503
jackwener merged 1 commit intojackwener:mainfrom
ByteYue:fix/ts-plugin-loading-500

Conversation

@ByteYue
Copy link
Collaborator

@ByteYue ByteYue commented Mar 27, 2026

Problem

Fixes #500

When a TS plugin is installed but esbuild is unavailable or transpilation fails silently, the plugin discovery attempts to import() the raw .ts file at runtime, causing:

⚠ Plugin hot-digest/aggregate.ts: Unknown file extension ".ts"

Root Cause

  1. transpilePluginTs() silently swallows all errors (bare catch {}), so if esbuild isn't available, no .js file is generated and no warning is shown
  2. discoverPluginDir() sees the .ts file with no .js companion and attempts direct import(), which fails on production Node.js (only works under tsx in dev mode)

Changes

src/discovery.ts

  • When a .ts plugin file has no compiled .js companion, skip the import and show an actionable warning:
    Plugin hot-digest/aggregate.ts: no compiled .js found. Run "opencli plugin update hot-digest" to re-transpile, or install esbuild.

src/plugin.ts

  • Upgrade "esbuild not found" message from log.debuglog.warn so users know TS plugins won't work
  • Log the outer catch error instead of silently swallowing it

Testing

  • All 50 existing plugin tests pass
  • Manual verification: removing .js from hot-digest plugin now shows a clear warning instead of crashing

…fails (jackwener#500)

When a TS plugin is installed but esbuild is unavailable or transpilation
fails silently, the plugin discovery would attempt to import() the raw
.ts file, causing 'Unknown file extension .ts' on production Node.js.

Changes:
- discovery.ts: Skip raw .ts import when no compiled .js exists; show
  an actionable warning guiding the user to re-transpile or install esbuild
- plugin.ts: Upgrade esbuild-not-found from debug to warn level; log
  the outer catch error instead of silently swallowing it

Closes jackwener#500
@ByteYue ByteYue requested a review from jackwener March 27, 2026 07:47
@jackwener jackwener merged commit 2ad1215 into jackwener:main Mar 27, 2026
23 checks passed
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.

[Bug]: 示例plugin无法正常加载

2 participants