{"record":{"id":"58e8ec8a82299688","repo":"payloadcms/payload","slug":"error-importing-migration-file-from-importpath","errorCode":null,"errorMessage":"Error importing migration file from ${importPath}","messagePattern":"Error importing migration file from (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/payload/src/database/migrations/getPredefinedMigration.ts","lineNumber":81,"sourceCode":"      })\n      process.exit(1)\n    }\n  } else if (importPath) {\n    // Path 2: Any other package or file path - use dynamic import\n    // Supports: package.json exports (e.g. @payloadcms/plugin-seo/migration) or absolute file paths\n    try {\n      const { downSQL, dynamic, imports, upSQL } =\n        await dynamicImport<MigrationTemplateArgs>(importPath)\n      return {\n        downSQL,\n        dynamic,\n        imports,\n        upSQL,\n      }\n    } catch (_err) {\n      if (importPath?.includes('/')) {\n        // We can assume that the intent was to import a file, thus we throw an error.\n        throw new Error(`Error importing migration file from ${importPath}`)\n      }\n      // Silently fail. If the migration cannot be imported, it will be created as a blank migration and the import path will be used as the migration name.\n      return {}\n    }\n  }\n  return {}\n}\n","sourceCodeStart":63,"sourceCodeEnd":89,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/database/migrations/getPredefinedMigration.ts#L63-L89","documentation":"Thrown by `getPredefinedMigration` when `payload migrate:create` (or create-from-file) is given a `--file` argument whose path contains `/` but fails to import. Because the slash implies a file/package path (not just a migration name), Payload treats the failure as an error rather than silently creating a blank migration. Causes include a missing file, a broken package export, or a migration module that throws on import.","triggerScenarios":"Running `payload migrate:create myName --file ./src/mig.ts` when the file does not exist or has a syntax error; `--file @somePkg/migration` where the package's export map lacks that subpath; a migration file whose top-level code throws at import time.","commonSituations":"Sharing a migration across projects via a package path that isn't exported; typos in the `--file` path; ESM/CJS mismatch causing the dynamic import to reject.","solutions":["Verify the path exists and is importable (`node -e \"import('./src/mig.ts')\"` or equivalent).","If pointing at a package subpath, ensure `package.json` `exports` exposes it.","Fix any syntax/runtime errors at the module's top level.","If you only wanted a name (not a file), drop the `/` from the argument so it silently falls back to a blank migration."],"exampleFix":"// before\npayload migrate:create myName --file ./src/nonexistent.ts\n// after\npayload migrate:create myName --file ./src/existing-migration.ts","handlingStrategy":"try-catch","validationCode":"import fs from 'fs'\nconst file = './src/my-migration.ts'\nif (file.includes('/') && !fs.existsSync(file)) {\n  throw new Error(`Migration source not found: ${file}`)\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runCLI(['migrate:create', name, '--file', file])\n} catch (err) {\n  if (/Error importing migration file/.test((err as Error).message)) {\n    // verify the file exists, has no syntax errors, and is exported correctly\n  }\n  throw err\n}","preventionTips":["Confirm the `--file` path resolves before running migrate:create.","Ensure package `exports` expose any subpath you import from.","Use a plain migration name (no `/`) when you want a blank template."],"tags":["database","migrations","cli","import","esm"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}