Closed DemonICOLI closed 4 months ago
same problem here
Also seeing this issue in our CI/CD using v3.39.0
Same problem in local and CI/CD pipelines, trying to investigate here
node LTS version 20.18.1 works.
@MordaCap this issue pertains to the Active LTS release (v22) rather than the Maintenance LTS release (v20)
I can see that this works on node version 22.11.0 and breaks on versions 22.12.0.
@austencollins this might be a duplicate of https://github.com/serverless/serverless/issues/12922#issuecomment-2526886276 is that correct?
Hey, this issue is caused by Node v22.12 due to a change in how it loads native ES modules
Support for loading native ES modules using require() had been available on v20.x and v22.x under the command line flag --experimental-require-module, and available by default on v23.x. In this release, it is now no longer behind a flag on v22.x.
With this feature enabled, Node.js will no longer throw ERR_REQUIRE_ESM if require() is used to load a ES module.
As a workaround, you can disable this experimental feature by setting the following environment variable before running Serverless:
export NODE_OPTIONS="--no-experimental-require-module"
Hi @eudoroolivares2016, Nope. This appears to be an issue related to a (breaking?) change in Node.js V22, distributed in one of its minor releases. A few other projects seem affected. We'll continue to look into this.
Hey everyone, we’ve just released v3.40.0, which resolves the Node v22.12 incompatibility. Feel free to update and give it a try.
Hey everyone, we’ve just released v3.40.0, which resolves the Node v22.12 incompatibility. Feel free to update and give it a try.
Works fine! There's just a warning that can be updated as well: https://github.com/serverless/serverless/issues/12963
Hey everyone, we’ve just released v3.40.0, which resolves the Node v22.12 incompatibility. Feel free to update and give it a try.
this fixed the issue! I'm now able to use Node 22.
We're seeing ERR_REQUIRE_ASYNC_MODULE
thrown at line 5 in require-with-import-fallback.js
RESOLVED: We resolved by disabling both experiments:
export NODE_OPTIONS="--no-experimental-detect-module --no-experimental-require-module"
This also happens with 3.40.0. Adding NODE_OPTIONS=--no-experimental-require-module
before sls package
doesn't fix it but it changes the error.
I wonder if the problem we are seeing is triggered by the experimental detect module flag that was enabled by default as of Node 22.7.0.
https://nodejs.org/api/cli.html#--no-experimental-detect-module
This seems to pose a problem for TypeScript:
https://github.com/microsoft/TypeScript/issues/56678
Our scenario may be the one described here:
Any insight would be appreciated.
4962 | Environment: linux, node 22.13.0, framework 3.39.0 (local), plugin 7.2.3, SDK 4.5.1
4963 | Docs: docs.serverless.com
4964 | Support: forum.serverless.com
4965 | Bugs: github.com/serverless/serverless/issues
4966 |
4967 | Error:
4968 | 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.
4969 | at ModuleJobSync.runSync (node:internal/modules/esm/module_job:392:13)
4970 | at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:329:47)
4971 | at loadESMFromCJS (node:internal/modules/cjs/loader:1411:24)
4972 | at Module._compile (node:internal/modules/cjs/loader:1544:5)
4973 | at Object..js (node:internal/modules/cjs/loader:1668:16)
4974 | at Module.load (node:internal/modules/cjs/loader:1313:32)
4975 | at Function._load (node:internal/modules/cjs/loader:1123:12)
4976 | at TracingChannel.traceSync (node:diagnostics_channel:322:14)
4977 | at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
4978 | at Module.require (node:internal/modules/cjs/loader:1335:12)
4979 | at require (node:internal/modules/helpers:136:16)
4980 | at module.exports (xxx/node_modules/serverless/lib/utils/require-with-import-fallback.js:5:12)
I am unfamiliar with serverless and only came across this from https://github.com/nodejs/node/issues/57520 - though from what I can tell https://github.com/serverless/serverless/pull/12950, it seems https://github.com/serverless/serverless/issues/12936#issuecomment-2576970783 could be fixed by adding || error.code === 'ERR_REQUIRE_ASYNC_MODULE'
in https://github.com/serverless/serverless/blob/main/lib/utils/require-with-import-fallback.js#L9 (use import()
to handle it if it's an async ESM).
Issue description
Just getting this error while running v2 on the node release v22.12.0
Context
No response