[▲ Vercel Community](/) · [Categories](/categories) · [Latest](/latest) · [Top](/top) · [Live](/live)

[Help](/c/help/9)

# Does serverless function supports require-ESM on Node 22?

160 views · 0 likes · 7 posts


Alvin (@alvin-leung-concept4) · 2025-10-30

<!-- Questions that get answered the fastest are the ones with relevant info included in the original post. Be sure to include all detail needed to let others see and understand the problem! -->

Does serverless function supports require-ESM on Node 22? In this [blog post](https://vercel.com/changelog/node-js-22-lts-is-now-available), it mentions “added support for require()ing synchronous ESM module graphs”. However, it doesn’t work in my deployment.

<!-- Current versus Expected behavior -->

## Current behavior

When I require an ESM-only library, e.g. `uuid`, Node throws `ERR_REQUIRE_ESM`.

## Expected behavior

Node doesn’t throw when requiring an ESM-only library.

<!-- Code, configuration, and steps that reproduce this issue -->

## Code

Repository: https://github.com/alvinleung1996/vercel-node22-require-esm-test

## Steps to reproduce

1. Install Node 22.18.0.
2. Run `yarn install`.
3. Run `vercel dev`.
4. Open `http://localhost:3000`
5. "require('uuid') error" should be "null".
6. Run `vercel deploy`.
7. "require('uuid') error" is "Error [ERR_REQUIRE_ESM]...".

<!-- Project information (URL, framework, environment, project settings) -->

## Project information

Deployment: https://vercel-node22-require-esm-test.vercel.app
Node.js Version: 22.x


Anshuman Bhardwaj (@anshumanb) · 2025-10-30

Hi @alvin-leung-concept4, I'm unable to recreate the local behaviour without using the `--experimental-require-module` flag. 

This functionality was initially introduced in Node.js versions 22.0.0 and 20.17.0 behind the `--experimental-require-module` flag. In later versions, specifically Node.js v23.0.0, the feature was no longer behind this flag, and in v23.5.0, the experimental warning associated with it was removed by default.

I'm digging more to find a solution for you. Will share here when I have a working example.


Anshuman Bhardwaj (@anshumanb) · 2025-10-30

Hi @alvin-leung-concept4, I was able to run your code on Vercel Nodejs v22 by providing the flag in the `NODE_OPTIONS` environment variable using `vercel.json`:

```json vercel.json
{
  "env": {
    "NODE_OPTIONS": "--experimental-require-module"
  },
  "rewrites": [{ "source": "/(.*)", "destination": "/api" }]
}
```


![CleanShot 2025-10-30 at 19.26.09@2x|690x112](upload://8gzjDwPWqeKGpaB03FlQJVvq23c.png)

I hope this solves your issue.


Alvin (@alvin-leung-concept4) · 2025-10-31

Thank you for your response.

I couldn't replicate your success. I have used your `vercel.json`, and it still doesn't work.

I see the flag `--no-experimental-require-module` in `process.execArgv` and it overrides the `--experimental-require-module` flag in `NODE_OPTIONS`. Not sure how your deployment has the opposite flag set.


Alvin (@alvin-leung-concept4) · 2025-10-31

Here is my result:

![image|690x89](upload://ePjryRZPBrxCVnbS9ot3vEgJgBD.png)


Anshuman Bhardwaj (@anshumanb) · 2025-10-31

Oh, I see. I deployed using Vercel CLI. Did you deploy using Vercel CLI or the GitHub integration?

By the way, I had changed the project structure a little bit:

![CleanShot 2025-10-31 at 14.16.38@2x|690x377](upload://bVba2SdOlhQZMveEnuCE4yYlbfE.png)


Alvin (@alvin-leung-concept4) · 2025-11-04

I have try deploying using both GitHub integration and Vercel CLI, and the deployments always have the flag `--no-experimental-require-module` set in `process.execArgv`.