I am facing a problem with the 'upper-case' module in my Node.js application. I'm trying to use the upper-case module to convert a string to uppercase, but I'm encountering an error related to ESM and require().
Node.js Version:
Node.js v20.9.0
Code:
var http = require('http');
var uc = require('upper-case');
http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.write(uc.upperCase("hello world!"));
res.end();
}).listen(5000);
console.log('Uppercase Server running...');
Error Message:
Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported.
Instead, change the require of index.js to a dynamic import().
I have tried using different syntax for require, but the issue persists. I have checked the 'upper-case' module's documentation and GitHub page for any known issues, but haven't found a solution.
As per the error state itself it no longer uses require.
If you really need you should try to import insted, Try something like below :
or else use javascript inbuilt functionality instead: