Skip to content

[BUG] @mastra/core npm aliases break pnpm deployments on Vercel (ERR_MODULE_NOT_FOUND) #15248

@SchoolyMammoth

Description

@SchoolyMammoth

Describe the Bug

Description

@mastra/core uses npm aliases in its dependencies (e.g., "@ai-sdk/provider-utils-v5": "npm:@ai-sdk/provider-utils@3.0.20"). These synthetic package names don't exist on npm — they only resolve if the package manager installs them into a flat node_modules. With pnpm's default strict symlink structure, they aren't available at runtime in Vercel's serverless environment.

Every server route crashes with:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@ai-sdk/provider-utils-v5'

The app works perfectly locally. This only manifests in the Vercel serverless runtime.

This appears to be the same root cause as #8775 (closed Oct 2025 against @mastra/core@0.20.2), but the problem persists in @mastra/core@1.24.0.

Stack

  • Framework: Nuxt 4 (Nitro serverless)
  • Package manager: pnpm 10
  • Deployment: Vercel (serverless functions)
  • Mastra packages: @mastra/core@^1.24.0, @mastra/memory@^1.15.0, @mastra/pg@^1.9.0, @mastra/ai-sdk@^1.3.3

What we tried (in order)

1. public-hoist-pattern in .npmrc — already in place, did not fix

public-hoist-pattern[]=@ai-sdk/*
public-hoist-pattern[]=@mastra/*

Hoisting patterns alone don't resolve npm aliases — pnpm still creates symlinks that Vercel's file tracer doesn't follow.

2. Adding aliased deps explicitly to package.json — did not fix

Added the aliased packages directly:

"@ai-sdk/provider-utils-v5": "npm:@ai-sdk/provider-utils@3.0.20"

Deployed, same error.

3. nitro.externals.inline for @mastra/* — partially worked

Inlined @mastra/* packages so the bundler resolves aliases at build time. The error shifted from referencing chunk-SE7ST47S.js to index.mjs — inlining partially worked but something still referenced the aliased package name at runtime.

Also tried installing the aliased AI SDK deps + inlining them together — still failed.

4. nitro.noExternals: true — broke the build

Switched to bundling everything. This broke because resend optionally imports @react-email/render which isn't installed. Worked around that with rollupConfig.external but the alias issue still wasn't fully resolved.

5. Also added @mastra/schema-compat aliased deps — still not enough

Discovered @mastra/schema-compat also uses npm aliases (zod-v3, zod-from-json-schema-v3). Added those too. Still failed — the alias whack-a-mole kept finding new unresolved packages.

6. Switching from pnpm to npm — aliases resolved but bundle too large

Removed pnpm entirely and switched to npm. npm's flat node_modules resolved all aliases natively, but the resulting Vercel serverless function exceeded the 250MB size limit, so this wasn't viable.

7. shamefully-hoist=true — did not fix

Reverted to pnpm with shamefully-hoist=true. Still uses symlinks under the hood, which Vercel's file tracer doesn't follow for aliased packages.

8. node-linker=hoisted — current workaround ✅

# .npmrc
node-linker=hoisted

This tells pnpm to create a flat, non-symlinked node_modules layout (like npm) while still benefiting from pnpm's deduplication, keeping the bundle under Vercel's 250MB limit.

Suggestion

The root cause is @mastra/core depending on npm aliases for AI SDK packages. This is fragile because:

  • pnpm (default mode) and Yarn PnP don't guarantee flat resolution of aliases
  • Serverless bundlers/tracers (Vercel, Netlify) may not follow symlinks
  • It requires users to configure their package manager to work around Mastra's internal dependency strategy

Ideally, @mastra/core would avoid npm aliases in its published package.json, or the Nuxt integration guide and deployment docs would document this requirement. (Note: the web framework deployment page currently covers Next.js and Astro but not Nuxt.)

Steps To Reproduce

  1. Create a Nuxt 4 app with @mastra/core@^1.24.0
  2. Use pnpm with default settings (no node-linker=hoisted)
  3. Deploy to Vercel
  4. Any server route that imports from @mastra/core will crash with ERR_MODULE_NOT_FOUND

Link to Minimal Reproducible Example

Workaround in place.

Expected Behavior

Server routes importing @mastra/core should work on Vercel with pnpm's default settings without requiring node-linker=hoisted.

Environment Information

Binaries:
    Node: 22.20.0
    npm: 10.9.3
    pnpm: 10.32.1

Verification

  • I have searched the existing issues to make sure this is not a duplicate
  • I have included sufficient information for the team to reproduce and understand the issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    AI SDKIssues with Mastra + AI-SDK toolkit and providersVercel DeploymentIssues in deploying a Mastra project to VercelbugSomething isn't workingeffort:highimpact:hightrio-wp

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions