Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
I am encountering an issue with PayloadCMS where the node-fetch package causes an error in my application. The error message is:
require() of ES Module /node_modules/node-fetch/src/index.js from /node_modules/payload/dist/uploads/getExternalFile.js not supported. Instead change the require of index.js to a dynamic import() which is available in all CommonJS modules.
It seems that node-fetch, which is now ESM-only, is being bundled by Webpack in a way that uses require() rather than import(). This causes the error because require() is not supported for ESM modules.
Environment Details
PayloadCMS version: 2.30.0
Node version: 20.16.0
To Reproduce
Install the required packages, including payload (which automatically installs node-fetch).
Create a media collection in PayloadCMS.
Upload an image to the media collection.
Attempt to crop the uploaded image and publish it.
When publishing, the following error appears:
require() of ES Module /node_modules/node-fetch/src/index.js from /node_modules/payload/dist/uploads/getExternalFile.js not supported.
Code Snippet
Here’s the problematic part of the getExternalFile function found in the node_modules/payload/dist/uploads/getExternalFile.js package:
Link to reproduction
No response
Describe the Bug
I am encountering an issue with PayloadCMS where the
node-fetch
package causes an error in my application. The error message is:It seems that
node-fetch
, which is now ESM-only, is being bundled by Webpack in a way that usesrequire()
rather thanimport()
. This causes the error becauserequire()
is not supported for ESM modules.Environment Details
To Reproduce
payload
(which automatically installsnode-fetch
).When publishing, the following error appears:
Code Snippet
Here’s the problematic part of the
getExternalFile
function found in thenode_modules/payload/dist/uploads/getExternalFile.js
package:Proposed Fix
Replacing the line:
with:
should resolve the error, allowing the application to function as intended.
Attachments
A video demonstrating the issue and the error message is attached for further context.
https://github.com/user-attachments/assets/fc58c04c-2551-45fc-98cf-abfe94248b4a
Payload Version
2.30.0
Adapters and Plugins
No response