From 98cbdb9c0c99e360a68a9dd921c86db70f58b6e1 Mon Sep 17 00:00:00 2001 From: Dan Ribbens Date: Mon, 19 Aug 2024 14:54:57 -0400 Subject: [PATCH] fix: readMigrationFiles error on windows --- .../payload/src/database/migrations/readMigrationFiles.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/payload/src/database/migrations/readMigrationFiles.ts b/packages/payload/src/database/migrations/readMigrationFiles.ts index 806f4d39177..705d240b6da 100644 --- a/packages/payload/src/database/migrations/readMigrationFiles.ts +++ b/packages/payload/src/database/migrations/readMigrationFiles.ts @@ -1,4 +1,5 @@ import fs from 'fs' +import { pathToFileURL } from 'node:url' import path from 'path' import type { Payload } from '../../index.js' @@ -35,9 +36,10 @@ export const readMigrationFiles = async ({ return Promise.all( files.map(async (filePath) => { + const filename = pathToFileURL(filePath) // eval used to circumvent errors bundling let migration = await eval( - `${typeof require === 'function' ? 'require' : 'import'}('${filePath.replaceAll('\\', '/')}')`, + `${typeof require === 'function' ? 'require' : 'import'}('${filename.href}')`, ) if ('default' in migration) migration = migration.default