yarn build generate a prerender nitro error while yarn dev works fine
I wanna deploy my Nuxt 3 app but I get this error although I can run yarn preview but the i18n translation isn't working.
when running yarn build and yarn preview, error I get on the console in the browser:
When I run yarn build
i18n.config.ts:
nuxt.config.ts:
package.json
Hi, thanks for opening an issue. It would be really helpful if you can provide a reproduction of this issue over Stackblitz please so that we can investigate/help better. You can use this as a starter - https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz
Okay thank you I will reproduce the error
I have the same issue when deploying in Netlify with pnpm
https://gregarious-kheer-2c80af.netlify.app/
You can check the source code here: https://github.com/JaimeTorrealba/renu-studios
And please let me know how to fix it
Same Problem here, my package.json:
"@nuxtjs/i18n": "^8.0.0-beta.12",
"nuxt": "^3.5.1",
Hi @ineshbose here is a reproduction of the error: https://stackblitz.com/edit/github-7hsxua?file=app.vue
Thank you 🙏
I get a similar error when I deploy on vercel or locally with npm run build .. local works fine
it seems it doesn't like export in config file which is similar to how others have defined it
one of the files comes with 500 in the browser so everything works except the translations when deployed
export default defineI18nConfig(() => ({
legacy: false,
locale: 'el',
messages: {
el: {
index: {
welcome: 'Καλωσηλθες'
}
},
en: {
index: {
welcome: 'Welcome'
}
}
}
}))
Browser Error:
Failed to load resource: the server responded with a status of 500 ()
i18n.options.2c8faeea.js:1 @nuxtjs/i18n Failed to fetch dynamically imported module: https://greek-evcars-git-i18n-nooul.vercel.app/__i18n__/prerender/cfcb45fa.js
u @ i18n.options.2c8faeea.js:1
ERROR (node:13072) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. 9:46:19 PM
(Use node --trace-warnings ... to show where the warning was created)
ERROR [nuxt] [request error] [unhandled] [500] Unexpected token 'export' 9:46:19 PM
at compileFunction (<anonymous>)
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:190:29)
at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
at async Promise.all (index 0)
ERROR (node:13072) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. 9:46:21 PM
├─ /__i18n__/prerender/301e041a.js (1569ms) (Error: [500] )
btw the above comment : https://github.com/nuxt-modules/i18n/issues/2097#issuecomment-1558910294 actually replicates the problem? I didn't see anything in the stackblitz terminal
Any news on this?
so far no
From v8.0.0-beta.12, we need to add "type": "module" to package.json of your nuxt project. https://v8.i18n.nuxtjs.org/getting-started/setup#packagejson
We are working on improving the system so that it can work without the "type": "module" specification, but at the moment that configuration is required.
From v8.0.0-beta.12, we need to add "type": "module" to package.json of your nuxt project. https://v8.i18n.nuxtjs.org/getting-started/setup#packagejson
We are working on improving the system so that it can work without the "type": "module" specification, but at the moment that configuration is required.
@kazupon Thank you! while I had followed this suggestion from stackoverflow about a week ago and it makes i18n work.. translation still doesn't work with JavaScript off which is very important for SEO and search indexing. Any ideas why is that?
here is a vercel build: vercel build that can be used to illustrate it along with Disable Javascript Chrome Extension
Issue 1:
I added the following plugin (in addition to the i18n.config.js) and it now translation works without JavaScript enabled BUT lang switcher is not working so I cannot change languages (url changes with adding /en and then it doesn't remove it for greek language) .. there is need for documentation improvement I guess or it should somehow work out of the box without an extra plugin.. not sure about langswitcher ..
i18n.server.js
import { createI18n } from 'vue-i18n'
import en from '../locale/en.js'
import el from '../locale/el.js'
export default defineNuxtPlugin(({ vueApp }) => {
const i18n = createI18n({
legacy: false,
globalInjection: true,
locale: 'el',
messages: {
en, el
}
})
vueApp.use(i18n)
})
LangSwitcher.vue
<script setup>
const { locale } = useI18n()
const switchLocalePath = useSwitchLocalePath()
</script>
<template>
<div class="language-switch">
<div v-if ="locale === 'el'">
<NuxtLink :to="switchLocalePath('en')"><img src="/uk.png" alt="English Flag" class="flag"/></NuxtLink>
</div>
<div v-else>
<NuxtLink :to="switchLocalePath('el')"><img src="/el.webp" alt="Greek Flag" class="flag"/></NuxtLink>
</div>
</div>
</template>
Issue 2:
I found another issue when javascript is off:
in the data store (pinia) in one of the methods I am doing
const nuxt = useNuxtApp()
nuxt.$i18n.t('insightGenerator.monthly', { param })
and this part is not translated with javascript off
You can check again with this different vercel build (after introducing i18n.server.js plugin) along with Disable Javascript Chrome Extension to see how lang switcher doesn't behave properly with javascript off
Although I added the type module still the same issue when I run yarn build
@wahibAbdou can't confirm - "type":"module" in package.json doesn't throw 500 for me anymore during build / browser run - but locally (not in vercel) build time takes 3-4 times more ~4 minutes. Also I have a lot of issues as I said above when javascript is off.. seems a lot of parts are not server rendered properly
Added type module to my package.json, still no translations in netlify environment
Same here, type module doesn't fix the error
I just make it work in cloudflare the trick is add "type": "module", in package.json and not modify the nitro config, avoid this kind of config in nuxt.config.ts
nitro: {
output: {
dir: "output",
serverDir: "output/server",
publicDir: "output/public",
},
},
And in the deployment configuration for cloudflare put this:
Works Like Charm!
Note: I'm using this versions of packages: "@nuxtjs/i18n": "^8.0.0-beta.12", "nuxt": "^3.5.1",
Unfortunately, I had to roll back to the old versions where everything was working fine here are these versions that work for me @nuxtjs/[email protected] [email protected] hope this helps for now till this gets solved in future updates.
First, I will comment before I respond.
Please comment if you are encountering the same problem as this issue. If the topic differs from the issue, open it as a new one. If so, please provide a minimal reproduction via GitHub repo or StackBliz! 🙏
@wahibAbdou
Hi @ineshbose here is a reproduction of the error: https://stackblitz.com/edit/github-7hsxua?file=app.vue
Thank you for your reproduction. However, I could not reproduce your issue. So, I seem that your reproduction is not setup for issue enviroment. Would you setup your enviroment with minimal reproduction?
Sorry I thought it was saved for some reason it wasn't lemme try again, thank you.
@wahibAbdou can't confirm - "type":"module" in package.json doesn't throw 500 for me anymore during build / browser run - but locally (not in vercel) build time takes 3-4 times more ~4 minutes. Also I have a lot of issues as I said above when javascript is off.. seems a lot of parts are not server rendered properly
Actually this is what I'm experiencing. SSR rendering of translations is not working properly in netlify/vercel. Error has disappeared btw by adding type module, so I guess we should open another issue.