-
Notifications
You must be signed in to change notification settings - Fork 9
Open
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
esbuild
bundler. - At runtime, Netlify loads
@netlify/blobs/dist/main.cjs
, which contains:…butconst runtimeUtils = require('@netlify/runtime-utils/dist/main.js')
@netlify/runtime-utils
is ESM-only. This triggersERR_REQUIRE_ESM
.
Expected behavior:
- Background Functions importing
@netlify/blobs
should work out of the box when using ESM. - The CJS build of
@netlify/blobs
should 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/blobs
version: 10.0.7/10.0.8@netlify/runtime-utils
version: 2.1.0- Next.js: 14.2.31
Workarounds tested:
-
Adding:
[functions] external_node_modules = ["@netlify/blobs", "@netlify/runtime-utils"]
to
netlify.toml
doesn'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/blobs
be adjusted not torequire()
ESM-only modules? - Alternatively, could
@netlify/blobs
mark@netlify/runtime-utils
as ESM-only and ensure the correct entrypoint is chosen consistently?
Metadata
Metadata
Assignees
Labels
No labels