Node.js App | Es Modules not working (ESM & .mjs)

#1
Hello.
I've been using openlitespeed for a long time. I love it and I am a big supporter.
I used php and node applications in my projects that I published on Openlitespeed.
I would like to share with you a mistake I discovered.
Screenshot_1.png

As you can see, instead of the normal .js extension, there is a .mjs extension. .mjs stands for es modules.
I discovered this error after I started using Nuxt v3.
After building my Nuxt 3 application, I wanted to run the server file as a node.js application on openlitespeed. But the page did not open.

Then I created an empty index.mjs file and writed the sample code block from the openlitespeed site's "Node.js Apps With OpenLiteSpeed" page and wrote it in.
JavaScript:
const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World form node js app.js\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});
Unfortunately it still didn't work. It worked fine when I changed the extension of the file to .js. But when I changed it back to .mjs it didn't work.

I solved my problem by creating proxy for now.
But when we want to use proxy for each application, we will always need to use unique port.

This is a temporary solution for me. But I am sure you will solve this problem in a short time.
I wish the developer team all the best. Thank you for the OpenLiteSpeed project.
 
#4
My 2 cents. It seems that even when I am using .js file extension, but setting "type":"module" in package.json it does not work.
Note: I am using node v16.13.1
 
Top