eyaltoledano/claude-task-master · error

The Grok CLI model function cannot be called with the new ke

Error message

The Grok CLI model function cannot be called with the new keyword.

What it means

The grokCli provider function is designed to be called as a plain function (grokCli(...)), not with `new`. JavaScript allows constructing ordinary functions, which would bind a wrong `this` and break the factory pattern, so the provider explicitly throws if `new.target` is set.

Source

Thrown at packages/ai-sdk-provider-grok-cli/src/grok-cli-provider.ts:75

		settings: GrokCliSettings = {}
	): LanguageModelV2 => {
		const mergedSettings = {
			...options.defaultSettings,
			...settings
		};

		return new GrokCliLanguageModel({
			id: modelId,
			settings: mergedSettings
		});
	};

	const provider = function (
		modelId: GrokCliModelId,
		settings?: GrokCliSettings
	) {
		if (new.target) {
			throw new Error(
				'The Grok CLI model function cannot be called with the new keyword.'
			);
		}

		return createModel(modelId, settings);
	};

	provider.languageModel = createModel;
	provider.chat = createModel; // Alias for languageModel

	// Add textEmbeddingModel method that throws NoSuchModelError
	provider.textEmbeddingModel = (modelId: string) => {
		throw new NoSuchModelError({
			modelId,
			modelType: 'textEmbeddingModel'
		});
	};

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Remove the `new` keyword and call the provider directly: `const grok = grokCli({...})`.
  2. Update code derived from outdated AI SDK provider examples.
  3. If wrapping, delegate without `new`: `const create = () => grokCli(settings);`

Example fix

// before
const provider = new grokCli({ apiKey });
// after
const provider = grokCli({ apiKey });
Defensive patterns

Strategy: validation

Validate before calling

// Convention check in code review/CI: flag `new grokCli` usage via lint rule (no-new-native-nonconstructor or custom rule)

Type guard

null

Try / catch

try { const p = new (grokCli as any)(settings); } catch (e) { if (e.message.includes('cannot be called with the new keyword')) { const p = grokCli(settings); } else { throw e; } }

Prevention

When it happens

Trigger: Writing `new grokCli({ ... })` or `new grokCli('model-id')` instead of calling it directly.

Common situations: Copy-pasting patterns from class-based providers; TypeScript auto-suggestions; older AI SDK examples where provider factories were constructor-style.

Related errors


AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29). Data as JSON: /api/errors/c31dcbdcac9e3c27. Report an issue: GitHub.