Skip to content

[BUG] Cloudflare deployer fails when PostgresStore is not used due to unnecessary Babel plugin execution #7811

@Naokiakazawa

Description

@Naokiakazawa

Describe the Bug

The Cloudflare deployer applies the postgres-store-instance-checker Babel plugin unconditionally, even when PostgresStore is not being used in the application. This causes build failures with the error:

ERROR: postgres-store-instance-checker plugin did not return code, there is likely a bug in the plugin.

Root Cause:
The postgres-store-instance-checker plugin is always included in the bundler options regardless of whether @mastra/pg is actually used as a dependency:

// Current problematic implementation
inputOptions.plugins = [
  virtual({ ... }),
  ...inputOptions.plugins,
  postgresStoreInstanceChecker(), // ← Always applied
  mastraInstanceWrapper(mastraEntryFile),
];

Impact:

  • Applications using other storage solutions (Redis, Memory, D1, etc.) fail to build
  • Applications with no storage at all fail to build
  • Unnecessary Babel transformations are performed even when not needed

Steps To Reproduce

  1. Create a Mastra app using Redis or Memory storage (no @mastra/pg dependency)
  2. Configure Cloudflare deployer
  3. Run build command
  4. Observe the plugin error

Expected Behavior

The postgres-store-instance-checker plugin should only be applied when:

  1. @mastra/pg package is actually installed as a dependency
  2. PostgresStore is being used in the application

Proposed Solution:

// Check if PostgresStore is being used before applying the plugin
const hasPostgresStore = (await this.deps.checkDependencies(['@mastra/pg'])) === `ok`;
if (hasPostgresStore) {
  plugins.push(postgresStoreInstanceChecker());
}

This would ensure:

  • ✅ PostgresStore users get proper instance validation
  • ✅ Non-PostgresStore users can build without errors
  • ✅ Better performance by skipping unnecessary transformations

Environment Information

  • @mastra/deployer-cloudflare 0.13.8-alpha.0
  • mastra 0.16.3
  • Nodejs v22.15.0
  • OS MacOS 15.6.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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions