• 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 Node.js install not working

Fabian H

Basic Pleskian
Using the node.js extension, the node server (port bound with express) cannot start as it seems.
The /var/log/httpd/error_log is giving this error:
Code:
App 1168143 output: /usr/share/passenger/helper-scripts/node-loader.js:80
App 1168143 output:     return originalRequire.apply(this, arguments);
App 1168143 output:                         ^
App 1168143 output: 
App 1168143 output: Error [ERR_REQUIRE_ESM]: require() of ES Module /var/www/vhosts/sitemap-finder.com/httpdocs/server.js from /usr/share/passenger/helper-scripts/node-loader.js not supported.
App 1168143 output: Instead change the require of server.js in /usr/share/passenger/helper-scripts/node-loader.js to a dynamic import() which is available in all CommonJS modules.
App 1168143 output:     at Module.require (/usr/share/passenger/helper-scripts/node-loader.js:80:25)
App 1168143 output:     at loadApplication (/usr/share/passenger/helper-scripts/node-loader.js:243:2)
App 1168143 output:     at setupEnvironment (/usr/share/passenger/helper-scripts/node-loader.js:214:2)
App 1168143 output:     at Object.<anonymous> (/usr/share/passenger/helper-scripts/node-loader.js:133:1) {
App 1168143 output:   code: 'ERR_REQUIRE_ESM'
App 1168143 output: }
App 1168143 output: 
App 1168143 output: Node.js v17.3.0
[ E 2021-12-23 11:44:24.1727 1166900/T1n age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /var/www/vhosts/sitemap-finder.com/httpdocs: The application process exited prematurely.
  Error ID: aff98d91
  Error details saved to: /tmp/passenger-error-qXrxkJ.html

[ E 2021-12-23 11:44:24.1772 1166900/T9 age/Cor/Con/CheckoutSession.cpp:276 ]: [Client 1-3] Cannot checkout session because a spawning error occurred. The identifier of the error is aff98d91. Please see earlier logs for details about the error.

The file /tmp/passenger-error-ioV4eJ.html does not exist anyway.

I try running with cli (/opt/plesk/node/17/bin/node server.js), there are no errors on startup, so modules seems to be installed correctly.
 
Ouh, I'm not sure how, but I did.
Right now, the app is running with Node v17.8.0 and the require() commands.
 
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)
 
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)
Thanks for sharing the link and the detail related to using it. This is helpful.
 
Back
Top