Dec 9, 2024
0
Level 1
Error [ERR_REQUIRE_ESM]: require()
Hi! I have a running application that was working fine. Its a shared host, in a cPanel. Today it started showing the error: 503 Service Unavailable The server is temporarily busy, try again later!
The logs show:
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/nsrinfor/repositories/yg1_ve/app.js from /usr/local/lsws/fcgi-bin/lsnode.js not supported.
app.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead either rename app.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /home/nsrinfor/repositories/yg1_ve/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
If I try changing the app.js (from the main folder, not resources) to app.cjs, the error 503 dissapears, but the page only renders:
It works! NodeJS 18.20.4
What am I missing?
Please or to participate in this conversation.