Skip to content

Conversation

@AlessioGr
Copy link
Member

@AlessioGr AlessioGr commented Nov 6, 2025

Fixes #14419.

In a live-preview enabled page, both the admin panel and the frontend initialize their own getPayload instances, each subscribing to HMR updates. In Next.js 16 with Turbopack, this setup can cause the server console to be flooded with errors like:

Error: Could not find the module "[project]/node_modules/.pnpm/[path-to-importmap-entry]" in the React Client Manifest. This is probably a bug in the React Server Components bundler.

These errors occur when an fs call tries to access the import map during the reload process.

Fix

The import map generation is now deferred using setTimeout and is no longer awaited. This prevents the problematic awaited fs access during HMR reloads.

Video that showcases this issue and the solution on the website template:

Screenshot.2025-11-05.at.19.36.10.mp4

Additional Improvements

Additionally, this PR prevents multiple reload operations from overlapping by skipping new reloads while one is already in progress.

This reduces redundant reload triggers when multiple getPayload instances are subscribed to the same HMR websocket, reducing the chance of something going wrong.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

📦 esbuild Bundle Analysis for payload

This analysis was generated by esbuild-bundle-analyzer. 🤖

Meta File Out File Size (raw) Note
packages/next/meta_index.json esbuild/index.js 755.53 KB ✅ No change
packages/payload/meta_index.json esbuild/index.js 1.23 MB ⚠️ +58 B (+0.0%)
packages/payload/meta_shared.json esbuild/exports/shared.js 163.07 KB ✅ No change
packages/richtext-lexical/meta_client.json esbuild/exports/client_optimized/index.js 279.48 KB ✅ No change
packages/ui/meta_client.json esbuild/exports/client_optimized/index.js 1.15 MB ✅ No change
packages/ui/meta_shared.json esbuild/exports/shared_optimized/index.js 14.39 KB ✅ No change
Largest paths These visualization shows top 20 largest paths in the bundle.

Meta file: packages/next/meta_index.json, Out file: esbuild/index.js

Path Size
../../node_modules ${{\color{Goldenrod}{ ████████████████████ }}}$ 80.2%, 601.84 KB
dist/views/Version ${{\color{Goldenrod}{ █▋ }}}$ 6.6%, 49.69 KB
dist/views/Document ${{\color{Goldenrod}{ ▌ }}}$ 2.1%, 15.43 KB
dist/views/List ${{\color{Goldenrod}{ ▎ }}}$ 1.4%, 10.46 KB
dist/views/Root ${{\color{Goldenrod}{ ▎ }}}$ 1.2%, 8.70 KB
dist/views/API ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 5.98 KB
dist/views/Versions ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 5.96 KB
dist/elements/Nav ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 5.53 KB
dist/views/Account ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 5.32 KB
dist/elements/DocumentHeader ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 4.81 KB
dist/views/Login ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 4.39 KB
dist/views/Dashboard ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 3.69 KB
dist/views/ForgotPassword ${{\color{Goldenrod}{ }}}$ 0.4%, 3.09 KB
dist/layouts/Root ${{\color{Goldenrod}{ }}}$ 0.4%, 2.91 KB
dist/templates/Default ${{\color{Goldenrod}{ }}}$ 0.4%, 2.83 KB
dist/views/CreateFirstUser ${{\color{Goldenrod}{ }}}$ 0.4%, 2.76 KB
dist/views/BrowseByFolder ${{\color{Goldenrod}{ }}}$ 0.3%, 2.60 KB
dist/views/CollectionFolders ${{\color{Goldenrod}{ }}}$ 0.3%, 2.46 KB
dist/views/ResetPassword ${{\color{Goldenrod}{ }}}$ 0.3%, 2.41 KB
dist/views/Logout ${{\color{Goldenrod}{ }}}$ 0.3%, 1.91 KB
(other) ${{\color{Goldenrod}{ ████▉ }}}$ 19.8%, 149.01 KB

Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js

Path Size
../../node_modules ${{\color{Goldenrod}{ █████████████████▏ }}}$ 68.9%, 841.07 KB
dist/fields/hooks ${{\color{Goldenrod}{ ▊ }}}$ 3.4%, 41.96 KB
dist/collections/operations ${{\color{Goldenrod}{ ▊ }}}$ 3.0%, 37.12 KB
dist/auth/operations ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 15.26 KB
dist/queues/operations ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 12.04 KB
dist/globals/operations ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 11.91 KB
dist/fields/config ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 11.80 KB
dist/utilities/configToJSONSchema.js ${{\color{Goldenrod}{ ▏ }}}$ 0.9%, 11.50 KB
dist/fields/validations.js ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 10.21 KB
dist/bin/generateImportMap ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 8.38 KB
dist/database/migrations ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 8.07 KB
dist/collections/config ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 7.88 KB
dist/uploads/fetchAPI-multipart ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 7.74 KB
dist/index.js ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 7.65 KB
dist/collections/endpoints ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 6.94 KB
dist/config/orderable ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 6.27 KB
dist/config/sanitize.js ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 5.53 KB
dist/auth/strategies ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 5.50 KB
dist/auth/endpoints ${{\color{Goldenrod}{ }}}$ 0.4%, 5.41 KB
dist/utilities/telemetry ${{\color{Goldenrod}{ }}}$ 0.4%, 5.31 KB
(other) ${{\color{Goldenrod}{ ███████▊ }}}$ 31.1%, 379.20 KB

Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js

Path Size
../../node_modules ${{\color{Goldenrod}{ ███████████████████▉ }}}$ 79.5%, 126.93 KB
dist/fields/validations.js ${{\color{Goldenrod}{ █▌ }}}$ 6.4%, 10.21 KB
dist/fields/baseFields ${{\color{Goldenrod}{ ▍ }}}$ 1.7%, 2.79 KB
dist/utilities/deepCopyObject.js ${{\color{Goldenrod}{ ▍ }}}$ 1.6%, 2.48 KB
dist/auth/cookies.js ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 1.55 KB
dist/utilities/flattenTopLevelFields.js ${{\color{Goldenrod}{ ▏ }}}$ 0.9%, 1.42 KB
dist/fields/config ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 1.28 KB
dist/utilities/flattenAllFields.js ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 943 B
dist/folders/utils ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 916 B
dist/utilities/unflatten.js ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 779 B
dist/utilities/sanitizeUserDataForEmail.js ${{\color{Goldenrod}{ }}}$ 0.4%, 713 B
dist/utilities/getFieldPermissions.js ${{\color{Goldenrod}{ }}}$ 0.4%, 651 B
dist/collections/config ${{\color{Goldenrod}{ }}}$ 0.4%, 570 B
dist/bin/generateImportMap ${{\color{Goldenrod}{ }}}$ 0.4%, 561 B
dist/auth/sessions.js ${{\color{Goldenrod}{ }}}$ 0.3%, 525 B
dist/utilities/getSafeRedirect.js ${{\color{Goldenrod}{ }}}$ 0.3%, 423 B
dist/utilities/deepMerge.js ${{\color{Goldenrod}{ }}}$ 0.3%, 413 B
dist/utilities/formatLabels.js ${{\color{Goldenrod}{ }}}$ 0.2%, 380 B
dist/utilities/appendUploadSelectFields.js ${{\color{Goldenrod}{ }}}$ 0.2%, 360 B
dist/utilities/transformColumnPreferences.js ${{\color{Goldenrod}{ }}}$ 0.2%, 348 B
(other) ${{\color{Goldenrod}{ █████▏ }}}$ 20.5%, 32.80 KB

Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js

Path Size
dist/features/blocks ${{\color{Goldenrod}{ ███▏ }}}$ 12.6%, 34.80 KB
dist/lexical/plugins ${{\color{Goldenrod}{ ██▉ }}}$ 11.5%, 31.68 KB
dist/lexical/ui ${{\color{Goldenrod}{ ██▏ }}}$ 8.8%, 24.36 KB
dist/features/experimental_table ${{\color{Goldenrod}{ ██▏ }}}$ 8.6%, 23.70 KB
dist/packages/@lexical ${{\color{Goldenrod}{ █▋ }}}$ 6.9%, 18.99 KB
dist/features/link ${{\color{Goldenrod}{ █▋ }}}$ 6.5%, 18.04 KB
dist/features/toolbars ${{\color{Goldenrod}{ █▌ }}}$ 6.4%, 17.75 KB
dist/features/upload ${{\color{Goldenrod}{ █▎ }}}$ 5.0%, 13.69 KB
dist/features/textState ${{\color{Goldenrod}{ █ }}}$ 4.0%, 11.08 KB
dist/features/relationship ${{\color{Goldenrod}{ ▊ }}}$ 3.2%, 8.96 KB
dist/lexical/utils ${{\color{Goldenrod}{ ▋ }}}$ 2.9%, 8.08 KB
dist/features/debug ${{\color{Goldenrod}{ ▋ }}}$ 2.7%, 7.39 KB
dist/utilities/fieldsDrawer ${{\color{Goldenrod}{ ▋ }}}$ 2.6%, 7.12 KB
dist/features/converters ${{\color{Goldenrod}{ ▋ }}}$ 2.5%, 7.04 KB
dist/lexical/config ${{\color{Goldenrod}{ ▍ }}}$ 1.8%, 5.08 KB
dist/features/lists ${{\color{Goldenrod}{ ▍ }}}$ 1.8%, 5.00 KB
dist/features/format ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 3.46 KB
dist/lexical/LexicalEditor.js ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 3.17 KB
dist/lexical/theme ${{\color{Goldenrod}{ ▏ }}}$ 0.9%, 2.62 KB
dist/features/indent ${{\color{Goldenrod}{ ▏ }}}$ 0.9%, 2.50 KB
(other) ${{\color{Goldenrod}{ █████████████████████▊ }}}$ 87.4%, 241.42 KB

Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js

Path Size
../../node_modules ${{\color{Goldenrod}{ ████████████▌ }}}$ 50.2%, 572.84 KB
dist/elements/FolderView ${{\color{Goldenrod}{ ▋ }}}$ 2.6%, 29.18 KB
dist/elements/BulkUpload ${{\color{Goldenrod}{ ▌ }}}$ 2.4%, 26.93 KB
dist/elements/WhereBuilder ${{\color{Goldenrod}{ ▍ }}}$ 1.5%, 16.70 KB
dist/views/Edit ${{\color{Goldenrod}{ ▎ }}}$ 1.4%, 16.03 KB
dist/elements/Table ${{\color{Goldenrod}{ ▎ }}}$ 1.4%, 15.44 KB
dist/fields/Relationship ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 15.40 KB
dist/forms/Form ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 15.12 KB
dist/fields/Blocks ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 12.89 KB
dist/fields/Upload ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 11.49 KB
dist/elements/PublishButton ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 8.75 KB
dist/providers/Folders ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 8.49 KB
dist/elements/QueryPresets ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 8.46 KB
dist/elements/LivePreview ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 8.38 KB
dist/elements/ListHeader ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 7.83 KB
dist/elements/HTMLDiff ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 7.81 KB
dist/fields/Array ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 7.55 KB
dist/views/CollectionFolder ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 7.37 KB
dist/views/List ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 6.96 KB
dist/elements/ReactSelect ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 6.91 KB
(other) ${{\color{Goldenrod}{ ████████████▍ }}}$ 49.8%, 568.38 KB

Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js

Path Size
dist/graphics/Logo ${{\color{Goldenrod}{ █████▋ }}}$ 22.6%, 3.12 KB
../../node_modules ${{\color{Goldenrod}{ ████▊ }}}$ 19.2%, 2.65 KB
dist/graphics/Icon ${{\color{Goldenrod}{ ██▊ }}}$ 11.0%, 1.52 KB
dist/utilities/formatDocTitle ${{\color{Goldenrod}{ ██▍ }}}$ 9.6%, 1.32 KB
dist/providers/TableColumns ${{\color{Goldenrod}{ █▌ }}}$ 6.2%, 862 B
dist/utilities/groupNavItems.js ${{\color{Goldenrod}{ █▍ }}}$ 5.9%, 814 B
dist/utilities/api.js ${{\color{Goldenrod}{ █▍ }}}$ 5.5%, 756 B
dist/elements/Translation ${{\color{Goldenrod}{ ▉ }}}$ 3.6%, 493 B
dist/utilities/handleTakeOver.js ${{\color{Goldenrod}{ ▊ }}}$ 3.2%, 440 B
dist/elements/withMergedProps ${{\color{Goldenrod}{ ▋ }}}$ 2.5%, 339 B
dist/elements/WithServerSideProps ${{\color{Goldenrod}{ ▍ }}}$ 1.7%, 232 B
dist/utilities/handleGoBack.js ${{\color{Goldenrod}{ ▎ }}}$ 1.2%, 168 B
dist/fields/mergeFieldStyles.js ${{\color{Goldenrod}{ ▎ }}}$ 1.2%, 159 B
dist/forms/Form ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 147 B
dist/utilities/abortAndIgnore.js ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 146 B
dist/utilities/hasSavePermission.js ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 136 B
dist/utilities/handleBackToDashboard.js ${{\color{Goldenrod}{ ▏ }}}$ 0.9%, 129 B
dist/utilities/findLocaleFromCode.js ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 84 B
dist/utilities/sanitizeID.js ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 77 B
dist/utilities/isEditing.js ${{\color{Goldenrod}{ }}}$ 0.4%, 59 B
(other) ${{\color{Goldenrod}{ ███████████████████▎ }}}$ 77.4%, 10.68 KB
Details

Next to the size is how much the size has increased or decreased compared with the base branch of this PR.

  • ‼️: Size increased by 20% or more. Special attention should be given to this.
  • ⚠️: Size increased in acceptable range (lower than 20%).
  • ✅: No change or even downsized.
  • 🗑️: The out file is deleted: not found in base branch.
  • 🆕: The out file is newly found: will be added to base branch.

@LucasMatuszewski
Copy link

LucasMatuszewski commented Nov 6, 2025

Thank you @AlessioGr

It's a little better - number of errors is reduced (skipped duplicate) and the order of compilation changed (setTimeout).
But I still get this errors when I add/change fields in Page collection on Website Template.
On Website template I get 18 errors, so usable. But on my prod app I get 91 errors (instead of >150 before), so still not usable.

The root issue is still in Next.js clearing cache in Turbopack (but not clearing module path referrals in Node.js) when we have full page load on route group change between (frontend) <--> (payload), introduced here:
https://github.com/vercel/next.js/pull/81664/files

But not sure if you can do anything more on your side. We would have to either force Turbopack to keep these modules in cache on route group change (like import them in /app/layout.ts only for dev) or remove path reference from node.js runtime (but Payload needs them so rather bad idea).

Video with reproduction
https://github.com/user-attachments/assets/f980f592-504c-46b7-9509-c7d56129819a

Reproduction for Website Template with your latest internal release + Mongo is here:
https://github.com/LucasMatuszewski/turbopack-error-reproduction/tree/next-16-0-1%2Bmongodb%2BPayload-3-63-0-internal-1544aa


BTW, the duplicated render on HRM changes is intentional to highlight issues, but I guess in this case it's good idea to prevent it :D


On my prod app I get below errors many times when installed 3.63.0-internal.15444aa.
Deleting node_modules didn't help.
But I guess it's temporary issue with internal release?

 ⚠ ./node_modules/.pnpm/@[email protected]_@[email protected][email protected]_490978066623562d033f4e6ceaddc848/node_modules/@payloadcms/storage-s3/dist
Package @aws-sdk/client-s3 can't be external
The request @aws-sdk/client-s3 matches serverExternalPackages (or the default list).
The request could not be resolved by Node.js from the project directory.
Packages that should be external need to be installed in the project directory, so they can be resolved from the output files.
Try to install it into the project directory by running npm install @aws-sdk/client-s3 from the project directory.


 ⚠ ./node_modules/.pnpm/@[email protected]_@opentelemetry+context-async-hooks@2._153b84fadc269a219c43133d3b6e5aea/node_modules/@payloadcms/plugin-sentry/dist/providers
Package @sentry/nextjs can't be external
The request @sentry/nextjs matches serverExternalPackages (or the default list).
The package resolves to a different version when requested from the project directory (10.23.0) compared to the package requested from the importing module (8.55.0).
Make sure to install the same version of the package in both locations.

EDIT: probably AWS and Sentry errors started after your change in serverExternalPackages in other PR this week.
For Sentry, can you please update from 8 to 10? Or I can override with pnpm.overrides.
About S3 - not sure, should I install it?

@LucasMatuszewski
Copy link

LucasMatuszewski commented Nov 6, 2025

I tested 3 more hypothesises:

  1. totally removing generateImportMap code (instead of setTimeout), doesn't fix the issue. We still have same errors. So it's not triggered by importMap generation.
  2. In isrManifest message we sometimes get only our FE app path, so I skipped setting cached.reload = true; if there is no /admin or /api in paths. It also didn't help (but maybe you should do this either way, if I understand correctly you trigger Payload reload also on FE app changes).
  3. Added setTimeout to cached.reload = true to give Turbopack more time to compile modules, but for 0 it changed nothing, for 500ms it just delayed errors, and for 2500ms it broke the app MongoNotConnectedError ;)

Logs with my changes in your index.js:

HRM onmessage event data: {
  type: 'isrManifest',
  data: {
    '/pl/formularz-zapytania': false,
    '/admin/collections/pages/68fa3ddb5241be84a75f65e6': false
  }
}
 GET /api/users/me 200 in 527ms (compile: 4ms, render: 523ms)
HRM onmessage event data: { type: 'building' }
HRM onmessage event data: { type: 'serverComponentChanges', hash: '247' }
>>> HRM lastISRManifest: {
  '/pl/formularz-zapytania': false,
  '/admin/collections/pages/68fa3ddb5241be84a75f65e6': false
}
>>> HRM hasPayloadPaths: true
 ✓ Compiled in 83ms
>>> HRM generateImportMap - SKIPPED
 ⨯ Error: Could not find the module "[project]/src/fields/CountChars.tsx#CountChars" in the React Client Manifest. This is probably a bug in the React Server Components bundler.
    at stringify (<anonymous>) {
  digest: '1401159352'
}

I don't know why we always have false for paths in isrManifest message. Could not find any info.


Unless you have better idea, I'm afraid that this must be fixed by Next.js.
IMHO they should not "fix memory leaks" by just removing code that was clearing node.js cache with module paths if these paths may be still requested when we use two route groups in the same time...

For now, dynamic import of importMap in /app/layout.ts works the best for me in dev.
After your changes from this PR it is almost not noticeable, I get only 3 Error: Could not find the module "[project]/src/app/(frontend)/[locale]/error.tsx#default" in the React Client Manifest instead of ~6 before ;P


My testing code if you would like to try it:

                let lastISRManifest = null;
                cached.ws = new WebSocket(process.env.PAYLOAD_HMR_URL_OVERRIDE ?? `${protocol}://localhost:${port}${prefix}${path}`);
                cached.ws.onmessage = (event)=>{
                    if (cached.reload instanceof Promise) {
                        // If there is an in-progress reload in the same getPayload
                        // cache instance, do not set reload to true again, which would
                        // trigger another reload.
                        // Instead, wait for the in-progress reload to finish.
                        return;
                    }
                    if (typeof event.data === 'string') {
                        const data = JSON.parse(event.data);
                        console.log('HRM onmessage event data:', data);
                        // Track isrManifest messages to determine which route group triggered changes
                        if (data.type === 'isrManifest' && data.data) {
                            lastISRManifest = data.data;
                        }
                        if (// On Next.js 15, we need to check for data.action. On Next.js 16, we need to check for data.type.
                        data.type === 'serverComponentChanges' || data.action === 'serverComponentChanges') {
                            // Only trigger reload if the last ISR manifest contained payload-related paths (/admin or /api)
                            // This prevents unnecessary reloads when changes are from frontend route group
                            console.log('>>> HRM lastISRManifest:', lastISRManifest);
                            const hasPayloadPaths = lastISRManifest && Object.keys(lastISRManifest).some(path =>
                                path.includes('/admin') || path.includes('/api')
                            );
                            console.log('>>> HRM hasPayloadPaths:', hasPayloadPaths);
                            if (hasPayloadPaths) {
                                cached.reload = true;
                            }
                        }
                    }
                };

@AlessioGr
Copy link
Member Author

In your repro, this even happens completely outside of HMR, when starting up a new dev server. So it is indeed completely unrelated to HMR / importmap generation.

I'll try creating a minimal reproduction outside of payload for this

@LucasMatuszewski
Copy link

LucasMatuszewski commented Nov 7, 2025

Yes, sometimes it happens also directly after dev server start. But not always, probably depending on cache content in .next folder.

HMR triggers these errors but is not causing them.
It's caused by mismatch between resolved paths to modules in Node.js runtime cache (paths still exists) and Turbopack compiled modules (cleared on route group change = full page load).

When I manually reverted changes introduced by Next.js in 15.5.0 by adding back code to deleteFromRequireCache (to remove paths also from Node.js runtime) all works fine, so this is the best temporary fix ;)

Ideally Next.js should e.g.

  1. provide a flag to keep the old logic before 15.5.0 (deleting paths from Node.js)
  2. or add a new config with list of modules to keep in cache (to prevent Turbopack removing them)

To test if it also fixes the issue for you you can in this file:
/node_modules/next/dist/server/dev/hot-reloader-turbopack.js (somewhere in .pnpm)
add back:

        const hasAppPaths = writtenEndpoint.serverPaths.some(({ path: p }) =>
            p.startsWith('server/app')
        )
    
        // Not available in:
        // - Pages Router (no server-side HMR)
        // - Edge Runtime (uses browser runtime which already disposes chunks individually)
        if (typeof __next__clear_chunk_cache__ === 'function') {
            __next__clear_chunk_cache__();
        }
        
        // TODO: Stop re-evaluating React Client once it relies on Turbopack's chunk cache.
        if (hasAppPaths) {
            _requirecache.deleteFromRequireCache(
                require.resolve(
                'next/dist/compiled/next-server/app-page-turbo.runtime.dev.js'
                )
            )
            _requirecache.deleteFromRequireCache(
                require.resolve(
                'next/dist/compiled/next-server/app-page-turbo-experimental.runtime.dev.js'
                )
            )
        }

& add export in /node_modules/next/dist/server/dev/require-cache.js

Object.defineProperty(exports, "deleteFromRequireCache", {
    enumerable: true,
    get: function() {
        return deleteFromRequireCache;
    }
});

@LucasMatuszewski
Copy link

BTW, I also tested new turbopackFileSystemCacheForDev config, but it doesn't make any difference. So FS cache doesn't prevent Turbopack from deleting your importMap.js modules on full page load ;)

@AlessioGr
Copy link
Member Author

Yep you're right - I don't think this is something we can easily fix within Payload. I've opened a Next.js issue here, with a very minimal reproduction: vercel/next.js#85883

I’m looping in the Next.js team and pointing them to your analysis so they have full context. Thanks for taking the time to really get to the bottom of this!

@AlessioGr
Copy link
Member Author

Closing this PR, as this does not fully fix the problem.

@AlessioGr AlessioGr closed this Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Turbopack HMR - Error: Could not find the module X in the React Client Manifest (Next.js 15.5.0 and 16.0.1)

3 participants