Skip to content

fix: call standalone isLocalTemplate function instead of thisArg method in runWatchMode#2067

Closed
chengyixu wants to merge 1 commit intoasyncapi:masterfrom
chengyixu:fix/2018-watch-mode-isLocalTemplate-crash
Closed

fix: call standalone isLocalTemplate function instead of thisArg method in runWatchMode#2067
chengyixu wants to merge 1 commit intoasyncapi:masterfrom
chengyixu:fix/2018-watch-mode-isLocalTemplate-crash

Conversation

@chengyixu
Copy link

Summary

Fixes #2018

Root Cause

In runWatchMode() in src/utils/generate/watcher.ts, the code on line 198 called:

if (!await thisArg.isLocalTemplate(...))

However, isLocalTemplate is a standalone exported function (line 11), not a method on the CLI command instance (thisArg). This causes an immediate TypeError: thisArg.isLocalTemplate is not a function crash after the initial generation completes when using --watch.

Fix

Call the isLocalTemplate() function directly (which is already in scope via the same file) instead of calling it as a method on thisArg:

// Before (broken):
if (!await thisArg.isLocalTemplate(path.resolve(...)))

// After (fixed):
if (!await isLocalTemplate(path.resolve(...)))

How to Reproduce (before fix)

asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template --watch --output ./out

After initial generation, the watcher crashes with:

TypeError: thisArg.isLocalTemplate is not a function

Testing

The fix is a one-line change calling the existing exported function directly. No logic change — only the call site is corrected.

…od in runWatchMode

Fixes asyncapi#2018

In runWatchMode(), the code called thisArg.isLocalTemplate() but isLocalTemplate
is a standalone exported function, not a method on the command instance (thisArg).
This caused a TypeError crash immediately after initial generation when using --watch.

Fix: call the imported isLocalTemplate() function directly instead of thisArg.isLocalTemplate().
@changeset-bot
Copy link

changeset-bot bot commented Mar 21, 2026

🦋 Changeset detected

Latest commit: c56de96

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@asyncapi/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@sonarqubecloud
Copy link

@chengyixu
Copy link
Author

Hi @asyncapi/cli-maintainers! All CI checks are passing for this PR. Happy to make any adjustments needed for merge. Thanks!

@github-project-automation github-project-automation bot moved this from To Triage to Done in CLI - Kanban Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG] Watch mode crashes with TypeError: thisArg.isLocalTemplate is not a function

2 participants