Vercel compile NodeJS ESM to CommonJS

I have a problem on my build with nodeJS with angular.
It used to build correctly but since today (maybe last week), when I build with the exact same command, and with some minor changes in the project, I keep having this logs :

[21:08:20.420] Warning: Node.js functions are compiled from ESM to CommonJS. If this is not intended, add "type": "module" to your package.json file.
[21:08:20.420] Compiling "chunk-2A5N5EV4.js" from ESM to CommonJS...
[21:08:20.471] Compiling "chunk-F53XS6YD.js" from ESM to CommonJS...
[21:08:20.476] Compiling "chunk-IWDGQLYK.js" from ESM to CommonJS...
[21:08:20.480] Compiling "chunk-M475QDW2.js" from ESM to CommonJS...
[21:08:20.484] Compiling "chunk-6BYLF33T.js" from ESM to CommonJS...
[21:08:20.489] Compiling "chunk-7VID3LXS.js" from ESM to CommonJS...
...
[21:08:31.168] Compiling "chunk-PFLFAM3J.js" from ESM to CommonJS...
[21:08:32.306] Compiling "main-V7NKN3TL.js" from ESM to CommonJS...
[21:08:33.227] Compiling "chunk-BFY2DBMX.js" from ESM to CommonJS...
[21:08:34.607] Compiling "chunk-V4YHAW2Y.js" from ESM to CommonJS...
[21:08:40.901] Build Completed in /vercel/output [4m]
[21:08:41.788] Deploying outputs...
[21:08:57.081] 
[21:08:57.449] Deployment completed

It first makes the project not workng anymore, and when I try the exact same command on local, it work perfectly and without this “post-compiling” step (note that’s appening after the build command I give in vercel configuration)

I wanted to know since when changes on this subject have been made, and how I can find an alternative in order to get the older behavior, since I can’t really change the configuration in package.json (I use Nx and I don’t have one in the application, only global and on the library and I don’t want to change the build system for the library since it’s published to npmjs and people are using it)

Thanks :slight_smile:

Since it’s an Angular project, I’m assuming it also uses TypeScript. So you should be able to fix it by including a tsconfig.json set for ESM.

Here’s an earlier post with a configuration example that’s helped in similar cases:

Nx also has the option to compile TypeScript packages to multiple formats, which might help you :slightly_smiling_face:

@amyegan thanks for your quick reply :slightly_smiling_face:

Unfortunatly this is already the setup I have in the project…
Also there weren’t new libraries or updates on it, and it worked well with library in commonJS

I’m just concerned about the fact that it was building without warning or error before, and now I have a warning, these wierd logs and the web site with an error in the console without any changes on the node version (also I tested by upgrading to node 20), dependencies or any configuration about vercel or the project itself…

If you want a closer look to the project here is the link GitHub - themesberg/flowbite-angular: Official Angular components built for Flowbite and Tailwind CSS on branch 107…

Also I don’t know if it’s important to say that the warning message and the building to commonJS happen on NodeJS function :

Warning: Node.js functions are compiled from ESM to CommonJS. If this is not intended, add "type": "module" to your package.json file.

@amyegan I have the confirmation that something on vercel have changed (not by me tho)
I tested to redeploy a branch. The main branch, it was working perfecly fine, I just went to the deploy of the branch, and click on redeploy button. No the exact same thing is happening on this deploy

No changes, no commit, no update in configurations, and I don’t have the same behavior on the exact same deploy

There’s something that changed on vercel side that I can’t control nice…

A recent package or runtime version update could cause build issues. What version of Node.js is set in project settings on Vercel? Are the dependencies pinned to exact version numbers (e.g. “package-name”: “1.2.3”), or are they set with flexible minimum versions (e.g. “package-name”: “^1.2.3”)?

Linking the Node.js runtime documentation in case it helps!

1 Like

The dependencies are pinned to the exact version I want, mostly because I don’t want to have a compatibility problem or an unwanted update

What are the Build and Development Settings? If you run vercel build from your local environment, do you also get the same error?