• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Issue Problems running NODE

DaniloVaron

New Pleskian
Server operating system version
AlmaLinux 9.2
Plesk version and microupdate number
Plesk Obsidian 18.0.56
I have problems uploading a web page with node

First I got this error

/usr/share/passenger/helper-scripts/node-loader.js:80
return originalRequire.apply(this, arguments);
^

Error [ERR_REQUIRE_ESM]: require() of ES Module /var/www/vhosts/deunacolombia.com/desarrollo.deunacolombia.com/deunacolombia-node/index.js from /usr/share/passenger/helper-scripts/node-loader.js not supported.
Instead change the require of index.js in /usr/share/passenger/helper-scripts/node-loader.js to a dynamic import() which is available in all CommonJS modules.
at Module.require (/usr/share/passenger/helper-scripts/node-loader.js:80:25)
at loadApplication (/usr/share/passenger/helper-scripts/node-loader.js:243:2)
at setupEnvironment (/usr/share/passenger/helper-scripts/node-loader.js:214:2)
at Object.<anonymous> (/usr/share/passenger/helper-scripts/node-loader.js:133:1) {
code: 'ERR_REQUIRE_ESM'
}

I tried a workaround from the same forum by creating an index.cjs file containing

import('./index.js').then(() => console.log('@@@@@@@ WORKED')).catch(e => console.log('@@@@@ @@ FAILED', e.message, e.stack));

making sure that the executable was that file.

1697122415811.png

Now the page has a 504 error

1697122487073.png
I use .ejs as templates and the page views are located here...
1697122609748.png

Does anyone have a solution please

Thanks
 
I have problems uploading a web page with node

First I got this error

/usr/share/passenger/helper-scripts/node-loader.js:80
return originalRequire.apply(this, arguments);
^

Error [ERR_REQUIRE_ESM]: require() of ES Module /var/www/vhosts/deunacolombia.com/desarrollo.deunacolombia.com/deunacolombia-node/index.js from /usr/share/passenger/helper-scripts/node-loader.js not supported.
Instead change the require of index.js in /usr/share/passenger/helper-scripts/node-loader.js to a dynamic import() which is available in all CommonJS modules.
at Module.require (/usr/share/passenger/helper-scripts/node-loader.js:80:25)
at loadApplication (/usr/share/passenger/helper-scripts/node-loader.js:243:2)
at setupEnvironment (/usr/share/passenger/helper-scripts/node-loader.js:214:2)
at Object.<anonymous> (/usr/share/passenger/helper-scripts/node-loader.js:133:1) {
code: 'ERR_REQUIRE_ESM'
}

I tried a workaround from the same forum by creating an index.cjs file containing

import('./index.js').then(() => console.log('@@@@@@@ WORKED')).catch(e => console.log('@@@@@ @@ FAILED', e.message, e.stack));

making sure that the executable was that file.

View attachment 24511

Now the page has a 504 error

View attachment 24512
I use .ejs as templates and the page views are located here...
View attachment 24513

Does anyone have a solution please

Thanks
The "document root" file is in..

In this folder are located all the views of the web page.
1697123282341.png
 
Solution:

I found the solution here:
Followed these steps and solved it.

  1. Create loader.cjs in your root file.
  2. Import your main file dynamically into the loader.cjs:


async function loadApp() {
await import('./index.js');
}
loadApp();

3. Go to your Node App in cPanel

4. In the "Application startup file", replace your main file with loader.cjs

5. Save and restart your app.

(if it doesn't work, destroy the project, then delete all files in the file manager and follow these steps again)
 
Back
Top