From d8f7034ab8f8d8b76185906c60c3b46ae4593d4d Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Wed, 4 Dec 2024 21:46:45 +0200 Subject: [PATCH] fix: `getPayload` generate import map only when used in Payload Admin Panel (#9371) After the change with removing `getPayloadHMR`, we do generate import map even outside of Next.js, which leads to errors when using in a project without it: ![image](https://github.com/user-attachments/assets/e8dc2af6-566b-443c-a6d8-8b02e719bd30) --- packages/payload/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/payload/src/index.ts b/packages/payload/src/index.ts index 465f8e697b4..a6f477edd15 100644 --- a/packages/payload/src/index.ts +++ b/packages/payload/src/index.ts @@ -807,7 +807,7 @@ export const getPayload = async ( // will reach `if (cached.reload instanceof Promise) {` which then waits for the first reload to finish. cached.reload = new Promise((res) => (resolve = res)) const config = await options.config - await reload(config, cached.payload) + await reload(config, cached.payload, !options.importMap) resolve() } @@ -815,7 +815,6 @@ export const getPayload = async ( if (cached.reload instanceof Promise) { await cached.reload } - if (options?.importMap) { cached.payload.importMap = options.importMap } @@ -839,6 +838,7 @@ export const getPayload = async ( ) { try { const port = process.env.PORT || '3000' + cached.ws = new WebSocket( `ws://localhost:${port}${process.env.NEXT_BASE_PATH ?? ''}/_next/webpack-hmr`, )