0

Other questions have been asked about this error e.g. here How to launch a sveltekit app on Plesk (Phusion Passenger)?

app.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename app.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /usr/home/michael/domains/michael.usermd.net/public_nodejs/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

I have followed these suggestions, switching between type: module and type: commonjs, which allows app.js to run, but it then requires all files with import, which Vite builds, to be .mjs files.

I am not able to change app.js to app.cjs to allow type: module to be used in package.json (not even sure whether that would do the trick) because that what my hosting company has set up and it can't be changed, and I can't access a Passengerfile.json, where apparently I would have access to this.

So after some testing I saw the manually changing .js files to .mjs allowed the import to function, but I can't do that for all files built, so was looking for a way to change the output of adapter() (adapter-node, I guess) just to change the .js to .mjs.

The thread https://github.com/vitejs/vite/issues/7963 suggests this code for the vite.config.js file but upon running vite build a warning is given that this setting will be overwritten by sveltekit and I guess by whatever is set in svelte.config.js. So far I have not seen anything in the documentation or in forums explaining how I can do what apparently can be done in vite.config.js in the svelte.config.js.

Anybody have any answers or suggestions on this? Or, is there now way out and I need to drop my hosting service and go with another kind of server that will make it a little bit easier for me to run a sveltekit app?


export default defineConfig({
  build: {
    rollupOptions: {
      output: {
        entryFileNames: `[name].[hash].mjs`,
        chunkFileNames: `[name].[hash].mjs`,
      },
    },
  },
});
MikeyB
  • 460
  • 1
  • 6
  • 22
  • If you want to change specifier and file extensions during a build you can use `@knighted/specifier`. Wrap it and create a plugin if you like. – morganney Aug 05 '23 at 14:45
  • You can try `vite-plugin-specifier` to change specifier and file extensions after the bundle is generated, or during a file transform. – morganney Aug 06 '23 at 21:33
  • Thanks for the suggestions. I've circumvented the problem by going with a proxy on the server and running my own node server, bypassing Phusion Passenger, app.js and the whole silly issue. – MikeyB Aug 07 '23 at 12:07

0 Answers0