2

I have built an app with SvelteKit and @sveltejs/adapter-node and deployed it to a server managed with Plesk via Git. I have activated and configured the node.js-Plugin and set all paths correctly, but I cannot run it with Phusion Passenger (which is the application server used by Plesk). I am getting the following 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/mydomain.host/build/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'
}

Node.js v17.6.0

Is there a solution to make my SvelteKit app run on Plesk?

I have already tried building an entry.cjs file with import("index.js"); in it (as suggested in this thread), but it did not work as well.

Florian
  • 31
  • 2

1 Answers1

6

This seems to be a general problem with Passenger. Their helper scripts aren't ES6 compatible.

Update: I found a way around it.

Create an entry.cjs file and use an async/await to dynamically import your applications entry file that you would normally set in plesk:

// entry.cjs
async function loadApp() {
    const { app } = await import("./app.js"); // this is your normal entry file - (index.js, main.js, app.mjs etc.)
}
loadApp()

Then in Plesk set your application entry file to ./entry.cjs

LessBorders
  • 151
  • 1
  • 3
  • I created a little package from your solution: https://www.npmjs.com/package/sveltekit-plesk-bridge – dritter Jul 04 '22 at 23:04