Fix flow_run ESM require error, bump to 1.2.2#37
Merged
Conversation
src/plugin/index.ts used inline require("path") / require("fs") inside
the file-path helpers (resolveFlowFile, versionsDir, listVersions,
readVersion), introduced when flow_list/flow_read/flow_publish landed.
The package is published as "type": "module" and tsc with NodeNext
emits the require() calls verbatim into ESM output, so any tool path
that hits a file: arg fails at runtime with "require is not defined".
Inline flows (no file:) sidestep resolveFlowFile and worked, masking
the bug.
Replace the lazy CJS requires with top-level "node:fs" / "node:path"
imports so the helpers work under ESM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
flow_run,flow_read, andflow_publishwere failing with"require is not defined"whenever a tool call passed afile:parameter — inline flows (nofile:) worked, which masked the bug.Root cause:
src/plugin/index.tshad lazyrequire("path")/require("fs")calls insideresolveFlowFile,versionsDir,listVersions, andreadVersion(introduced whenflow_list/flow_read/flow_publishlanded). The package is published as"type": "module"andtscwithNodeNextemitsrequire()verbatim into the ESM output, so the calls blow up at runtime in the plugin loader.Fix: replace the inline CJS requires with top-level
import * as fs from "node:fs"/import * as path from "node:path"so the helpers work under ESM.Test plan
npm run build— clean, norequire()indist/plugin/index.jsnode -e "import('./dist/plugin/index.js')"loads cleanly as ESMv1.2.2release →publish.ymlships to npm → re-pull on a VPS and confirmflow_runwithfile:succeeds