N
Nuxt2mo ago
DeVoresyah

Build Nuxt 3 as CommonJS

Hello, is there any ways to make Nuxt 3 build output as CommonJS instead of ESM ? The reason is I want to deploy my app into shared hosting using cpanel and they only support node app with CommonJS
5 Replies
brunomgmateus
brunomgmateus2mo ago
Would love to know more about this, having the same issue, App used to work fine until nuxt 3.11.x. Then somehow something changed, not quite sure what. I've usually had it working with a loading script, appstart.cjs.
async function loadApp() {
await import("./.output/server/index.mjs")
}

loadApp()
async function loadApp() {
await import("./.output/server/index.mjs")
}

loadApp()
This usually would load, but now it doesn't...
DeVoresyah
DeVoresyah2mo ago
do you found any solution @brunomgmateus ?
brunomgmateus
brunomgmateus5w ago
I've also tried just loading:
// appstart.cjs
import('./.output/server/index.mjs')
// appstart.cjs
import('./.output/server/index.mjs')
and so far has been working. But on Nuxt 3.11 Sorry for the late reply, but just to let you know that I've come accross an issue where, if you're using the setting "experimental.writeEarlyHints" in nuxt.config.ts, it breaks production version in cPanel, Plesk (and other serverrs that use either nginX or Phusion Passenger). This was true for the latest Nuxt version.
DeVoresyah
DeVoresyah5w ago
so I guess we cannot deploy to shared hosting anymore cuz I also need latest version of nuxt
brunomgmateus
brunomgmateus5w ago
You just need to disable the "experimental.writeEarlyHints" in nuxt config. SHould work well
Want results from more Discord servers?
Add your server