Resolving import.meta.url undefined errors in Braintrust eval CLI

Last updated: February 20, 2026

This issue is applicable to customers matching these conditions

Plans: Any

Deployments: Any

Use case: eval CLI with packages using ESM imports like import.meta.url

Summary

Error: The Braintrust eval CLI fails with "import.meta.url is undefined" errors when evaluating packages that use ESM imports.

Cause: The CLI bundles packages during evaluation, losing ESM module context and causing import.meta.url to be undefined.

Solution: Use the --external-packages flag to prevent bundling of packages that require ESM context.

Resolution Steps

Step 1: Identify packages using ESM imports

Look for packages in your evaluation code that use import.meta.url or other ESM-specific features.

Step 2: Add external packages flag

Use the --external-packages flag to mark these packages as external dependencies, for example:

braintrust eval eval.ts --external-packages @mastra/core,@mastra/observability

Step 3: Test the evaluation

Run your evaluation again to confirm the error is resolved. The packages will now be loaded directly from node_modules with proper ESM context.