Skip to content

[JS] abortSignal does not work with dotprompt #3348

@chrisvariety

Description

@chrisvariety

Describe the bug
When combining dotprompt (ai.prompt) with abortSignal, an error is thrown:

TypeError [ERR_INVALID_THIS]: Value of "this" must be of type EventTarget
    at Object.addEventListener (node:internal/event_target:596:13)
    at buildFetchOptions (/Users/chrismcc/workspace/lexikon/node_modules/@google/generative-ai/dist/index.js:450:15)
    at constructModelRequest (/Users/chrismcc/workspace/lexikon/node_modules/@google/generative-ai/dist/index.js:385:55)
    at makeModelRequest (/Users/chrismcc/workspace/lexikon/node_modules/@google/generative-ai/dist/index.js:391:41)
    at generateContent (/Users/chrismcc/workspace/lexikon/node_modules/@google/generative-ai/dist/index.js:868:28)
    at /Users/chrismcc/workspace/lexikon/node_modules/@google/generative-ai/dist/index.js:1188:25
    at async ChatSession.sendMessage (/Users/chrismcc/workspace/lexikon/node_modules/@google/generative-ai/dist/index.js:1211:9)
    at async callGemini (/Users/chrismcc/workspace/lexikon/node_modules/@genkit-ai/googleai/lib/gemini.js:1103:26)
    at async /Users/chrismcc/workspace/lexikon/node_modules/@genkit-ai/googleai/lib/gemini.js:1149:11
    at async /Users/chrismcc/workspace/lexikon/node_modules/@genkit-ai/core/lib/action.js:244:14 {
  code: 'ERR_INVALID_THIS',
  traceId: '40bd7c4a75cb583503c9026df4376d04',
  ignoreFailedSpan: true
}

To Reproduce

Very simple reproduction:

import { googleAI } from '@genkit-ai/googleai';
import { genkit } from 'genkit';

const ai = genkit({
  plugins: [googleAI()]
});

const testPrompt = ai.prompt('test');

const main = async () => {
  const { text } = await testPrompt(
    {},
    { abortSignal: AbortSignal.timeout(1000) }
  );

  console.log(text);
};

main().catch(console.error);

My test.prompt file in a prompts directory:

---
model: googleai/gemini-2.5-flash
---

This is a test prompt.

Expected behavior
abortSignal would be passed correctly without error.

Screenshots
n/a

Runtime (please complete the following information):

  • OS: MacOS
  • Version Sequoia 15.5

** Node version
v22.14.0

(also reproduces on v24.4.1)

Additional context
Maybe related to #3268

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingjs

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions