You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Node now allows using require() to import ES modules, ERR_REQUIRE_ESM is not triggered.
But if the module containes top-level await, ERR_REQUIRE_ASYNC_MODULE is triggered and it's not handled.
The following gulpfile.mjs contains top-level await.
In Node 20, this works.
In Node 22, this throws ERR_REQUIRE_ASYNC_MODULE.
$ gulp
Error [ERR_REQUIRE_ASYNC_MODULE]: require() cannot be used on an ESM graph with top-level await. Use import() instead. To see where the top-level await comes from, use --experimental-print-required-tla.
at ModuleJobSync.runSync (node:internal/modules/esm/module_job:392:13)
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:329:47)
at Object.loadESMFromCJS [as .mjs] (node:internal/modules/cjs/loader:1414:24)
at Module.load (node:internal/modules/cjs/loader:1318:32)
at Function._load (node:internal/modules/cjs/loader:1128:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:219:24)
at Module.require (node:internal/modules/cjs/loader:1340:12)
at require (node:internal/modules/helpers:138:16)
at requireOrImport (/home/***/.nvm/versions/node/v22.12.0/lib/node_modules/gulp/node_modules/gulp-cli/lib/shared/require-or-import.js:20:11) {
code: 'ERR_REQUIRE_ASYNC_MODULE'
}
Version:
node: v22.12.0
npm: v10.9.0
gulp: CLI version: 3.0.0, Local version: 5.0.0
The text was updated successfully, but these errors were encountered:
Description
Node now allows using
require()
to import ES modules,ERR_REQUIRE_ESM
is not triggered.But if the module containes top-level await,
ERR_REQUIRE_ASYNC_MODULE
is triggered and it's not handled.The following gulpfile.mjs contains top-level await.
In Node 20, this works.
In Node 22, this throws
ERR_REQUIRE_ASYNC_MODULE
.Sample of gulpfile
Terminal output
Version:
The text was updated successfully, but these errors were encountered: