Skip to content

[Bug]: npx medusa db:generate fails with undefined snapshotPath #14152

@enable-davidlin

Description

@enable-davidlin

Package.json file

{
  "name": "medusa-migration-bug-repro",
  "version": "0.0.1",
  "description": "Minimal reproduction repository for Medusa migration generation bug with undefined snapshotPath",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "scripts": {
    "build": "medusa build",
    "seed": "medusa exec ./src/scripts/seed.ts",
    "start": "medusa start",
    "dev": "medusa develop",
    "test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
    "test:integration:modules": "TEST_TYPE=integration:modules NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
    "test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit"
  },
  "dependencies": {
    "@medusajs/admin-sdk": "2.11.3",
    "@medusajs/cli": "2.11.3",
    "@medusajs/framework": "2.11.3",
    "@medusajs/medusa": "2.11.3"
  },
  "devDependencies": {
    "@medusajs/test-utils": "2.11.3",
    "@swc/core": "^1.7.28",
    "@swc/jest": "^0.2.36",
    "@types/jest": "^29.5.13",
    "@types/node": "^20.12.11",
    "@types/react": "^18.3.2",
    "@types/react-dom": "^18.2.25",
    "jest": "^29.7.0",
    "prop-types": "^15.8.1",
    "react": "^18.3.1",
    "react-dom": "^18.3.1",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.2",
    "vite": "^5.4.14",
    "yalc": "^1.0.0-pre.53"
  },
  "engines": {
    "node": ">=20"
  }
}

Node.js version

v25.2.1

Database and its version

PostgreSQL 17

Operating system name and version

macOS 15.6.1

Browser name

No response

What happended?

When attempting to generate migrations for a custom Medusa module with existing migration/snapshot files, the command fails because snapshotPath is undefined in the migration generation process.

Steps to Reproduce

  • Install using npx create-medusa-app@latest my-medusa-store
  • Create a custom Medusa module with a model definition
  • Run command npx medusa db:generate module_name, check migration folder and snapshot JSON file is created.
  • Make a change to the model definition
  • Run command npx medusa db:generate module_name again.
  • Observe the error

Expected behavior

Migration file gets generated

Actual behavior

Following error:

error:   Failed with error The "path" argument must be of type string. Received undefined
error:   The "path" argument must be of type string. Received undefined
TypeError: The "path" argument must be of type string. Received undefined
    at join (node:path:1339:7)
    at Migrations.migrateSnapshotFile (/Users/davidlin/Code/loyal/medusa/my-test-store/node_modules/@medusajs/utils/src/migrations/index.ts:213:32)
    at async Migrations.generate (/Users/davidlin/Code/loyal/medusa/my-test-store/node_modules/@medusajs/utils/src/migrations/index.ts:87:7)
    at async AsyncFunction.<anonymous> (/Users/davidlin/Code/loyal/medusa/my-test-store/node_modules/@medusajs/utils/src/modules-sdk/migration-scripts/migration-generate.ts:58:28)
    at async generateMigration (/Users/davidlin/Code/loyal/medusa/my-test-store/node_modules/@medusajs/modules-sdk/src/loaders/utils/load-internal.ts:502:9)
    at async MedusaModule.migrateGenerate (/Users/davidlin/Code/loyal/medusa/my-test-store/node_modules/@medusajs/modules-sdk/src/medusa-module.ts:792:9)
    at async run (/Users/davidlin/Code/loyal/medusa/my-test-store/node_modules/@medusajs/modules-sdk/src/medusa-app.ts:557:9)
    at async Promise.allSettled (index 0)
    at async executeNext (/Users/davidlin/Code/loyal/medusa/my-test-store/node_modules/@medusajs/utils/src/common/execute-with-concurrency.ts:19:22)
    at async Promise.allSettled (index 0) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Link to reproduction repo

npx create-medusa-app@latest my-medusa-store

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions