-
Notifications
You must be signed in to change notification settings - Fork 12
Description
When using @netlify/blobs in a Netlify Background Function that is otherwise fully ESM, the deployed background function fails with the following runtime error:
{
"errorType": "Error",
"errorMessage": "require() of ES Module /var/task/node_modules/@netlify/runtime-utils/dist/main.js from /var/task/node_modules/@netlify/blobs/dist/main.cjs not supported.\nInstead change the require of main.js in /var/task/node_modules/@netlify/blobs/dist/main.cjs to a dynamic import() which is available in all CommonJS modules.",
"code": "ERR_REQUIRE_ESM",
"stack": [
"Error [ERR_REQUIRE_ESM]: require() of ES Module /var/task/node_modules/@netlify/runtime-utils/dist/main.js from /var/task/node_modules/@netlify/blobs/dist/main.cjs not supported.",
"Instead change the require of main.js in /var/task/node_modules/@netlify/blobs/dist/main.cjs to a dynamic import() which is available in all CommonJS modules.",
" at TracingChannel.traceSync (node:diagnostics_channel:322:14)",
" at Object.<anonymous> (/var/task/node_modules/@netlify/blobs/dist/main.cjs:42:28)"
]
}Steps to reproduce:
- Create a Netlify Background Function with:
import { getStore } from '@netlify/blobs';
- Deploy with the default
esbuildbundler. - At runtime, Netlify loads
@netlify/blobs/dist/main.cjs, which contains:…butconst runtimeUtils = require('@netlify/runtime-utils/dist/main.js')
@netlify/runtime-utilsis ESM-only. This triggersERR_REQUIRE_ESM.
Expected behavior:
- Background Functions importing
@netlify/blobsshould work out of the box when using ESM. - The CJS build of
@netlify/blobsshould notrequire()an ESM-only dependency.
Actual behavior:
- Deploy ends up using the CJS build of
@netlify/blobs, which fails because itrequire()s an ESM-only file from@netlify/runtime-utils.
Environment:
- Netlify Functions runtime: Node 22
- Bundler: default
@netlify/build: 35.1.2@netlify/plugin-nextjs: 5.12.1@netlify/blobsversion: 10.0.7/10.0.8@netlify/runtime-utilsversion: 2.1.0- Next.js: 14.2.31
Workarounds tested:
-
Adding:
[functions] external_node_modules = ["@netlify/blobs", "@netlify/runtime-utils"]
to
netlify.tomldoesn't work. -
Replacing:
import { getStore } from '@netlify/blobs';
with:
const { getStore } = await import('@netlify/blobs');
doesn't work.
Request:
- Could the CJS build of
@netlify/blobsbe adjusted not torequire()ESM-only modules? - Alternatively, could
@netlify/blobsmark@netlify/runtime-utilsas ESM-only and ensure the correct entrypoint is chosen consistently?
dtuite