electricitymaps / electricitymaps-contrib

A real-time visualisation of the CO2 emissions of electricity consumption
https://app.electricitymaps.com
GNU Affero General Public License v3.0
3.49k stars 926 forks source link

Incompatibility with Node.js 20 #5984

Closed VIKTORVAV99 closed 10 months ago

VIKTORVAV99 commented 11 months ago

Description

It seems like we are incompatible with nodejs 20.

TODO

madsnedergaard commented 10 months ago

I am getting this error now when trying to run the map:

Screenshot 2023-11-03 at 10 20 11

Ran:

travellingprog commented 10 months ago

@madsnedergaard

The short explanation is that your issue is caused by a Node bug that is not present in the latest Node v20 (at the time of writing, v20.9.0). This is why this issue did not occur in the CI environment If you run nvm install 20, that should get you the latest version. I believe we should also now update the Earthfile to have FROM node:20 rather than FROM node:20.6. FROM node:20-bookworm would also be good if we want to lock in the major Debian version. Let me know what you think.

I was able to reproduce your issue with Node v20.6.1, and was able to see that it got fixed in Node v20.8.0. Looked at the Node changelog and found that this was the commit for the fix: https://github.com/nodejs/node/pull/49655.

Furthermore, there is now a .node-version file in both the web/ and mockserver/ folders. That file only has 20 in it, so that in our CI environment, we always use the latest v20. That file is supported by multiple Node version managers, but unfortunately nvm is still not one of them, despite a long opened issue. I recommend fnm personally. With that tool installed, you can run fnm install in a folder with a .node-version file, and it will always install (if necessary) and use the indicated Node version.

And finally, a quick warning. Once you change to the latest v20, check that pnpm exec node --version and pnpm exec which node output what you expect (that PNPM is using the Node from your version manager). I found out, while trying to reproduce your issue, that I had a global config use-node-version setting that was loading Node from a PNPM environment rather than my fnm version.

madsnedergaard commented 10 months ago

Oh, thanks for the detailed answer! 🙏