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`,
},
},
},
});