Skip to main content
Applies to:


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:
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.

Troubleshooting

Multiple packages need external flag

Separate package names with commas without spaces:
braintrust eval eval.ts --external-packages package1,package2,package3

Still getting bundling errors

If you continue to see import.meta.url errors, check for additional packages in your dependency tree that use ESM imports and add them to the external packages list.