i18n: Not work SPA (`ssr: false`)
Environment
- Operating System: Linux
- Node Version: v16.14.2
- Nuxt Version: 3.4.2
- Nitro Version: 2.3.3
- Package Manager: yarn@1.22.19
- Builder: vite
- User Config: srcDir, ssr, typescript, hooks, build, css, vite, modules, i18n
- Runtime Modules: @nuxtjs/i18n@8.0.0-beta.11
- Build Modules: -
Reproduction
https://stackblitz.com/edit/github-xhfdq1-de15an
Describe the bug
Run “yarn build”. Then browse to “.nuxt/dist/client/_nuxt/i18n.options.*.js”. It’s content will look like this:
import { _ as r, s as index } from './entry.075876a4.js';
async function _(n) {
const e = await r(() => import('./i18n.config.15578b8d.js'), [], import.meta.url).then(
(t) => t.default || t,
),
a = index.isFunction(e) ? await e(n) : index.isObject(e) ? e : {};
{
let t = null;
try {
const o = '/i18n-config-5fcc7ca7.js'; // <---------------------------- This file is not created
t = await r(() => import(o), [], import.meta.url).then((s) => s.default || s);
} catch (error) {
console.error(format(error.message));
}
return (a.messages = t || {}), a;
}
}
export { _ as default };
Imported file " ‘/i18n-config-5fcc7ca7.js’;" (with the dashes) is not created at all, therefore it breaks.
Additional context
I already opened a issue in the nuxt tracker (https://github.com/nuxt/nuxt/issues/20518) but now i am wondering if it is rather related to the module. If not it can be closed here.
Logs
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 4
- Comments: 34
Commits related to this issue
- * Lock @nuxtjs/I18n at 8.0.0.beta11 to avoid issue in beta12 https://github.com/nuxt-modules/i18n/issues/2029 — committed to PikaSer-Cosmos/pikaser-website-main by PikachuEXE a year ago
- fix: not work SPA (`ssr: false`) mode resolve #2029 — committed to nuxt-modules/i18n by kazupon a year ago
- fix: not work SPA (`ssr: false`) mode (#2099) resolve #2029 — committed to nuxt-modules/i18n by kazupon a year ago
- fix: not work SPA (`ssr: false`) mode (#2099) resolve #2029 — committed to DarthGigi/i18n by kazupon a year ago
1 set
package.json2 install
@nuxtjs/i18n-edge3 and change
nuxt.config.tstoworks for me.
nuxt 3.5.2 ssr:false, beta-12
Same here ✋ nuxt 3.5.0 ssr:false, beta-12
Downgrading to beta-11 fixes it for me as well
I got a different error now:
After many hours of trying different combinations this one worked for me:
8.0.0-beta.12-28113576.7bc33c3nuxt.config.tsi18n.config.tstonuxt.i18n.config.tsWorks for:
thanks to gbyesiltas I could also solve the problem, but I had to make a small change. Installing the @nuxtjs/i18n-edge isn’t enough, you should also register it as module.
So this is wrong (for now):
modules: [["@nuxtjs/i18n", i18nConfig]],Instead do this:
modules: ['@nuxtjs/i18n-edge'],and put your config like this:
I think this will be unnecessary after bug fix goes in to the next (main) branch.
For me the working combo was: 1- Update to
@nuxtjs/i18n-edge(I had to also delete package-lock) 2- Add"type": "module"to package.json 3- Did not usei18n.config.tsas the config file name. Rather usednuxt.i18n.config.tsbut the exact name doesn’t matter. I did it to avoid auto-importing of the configuration 4- Onnuxt.config.tsused the object way of providing module options instead of the array syntax:related issue https://github.com/nuxt-modules/i18n/issues/2156
When the same locale file (
.jsor.ts) as common logics onlangDiroption, nuxt i18n module doesn’t work forssr: false. it’s acknowledged that there is a bug.Thank you
Thanks @gbyesiltas I deleted the “package.lock.json” or “yarn.lock” file and redid a “yarn install”. I used @nuxtjs/i18n-edge and added “type”: “module” in package.json. Great work.
I think it can help others too
Mine was already with
type module, and it does not workNot sure if this is the right issue … I’m getting an error like the one reported in https://github.com/nuxt-modules/i18n/issues/2077 but I cannot see the import
e82347bastated as missing in the error message (ERROR [nuxtjs:i18n-resource-dynamic] Plugin error - Unable to get file name for unknown file "e82347ba".) being used anywhere in the code, so I don’t know if I’m right when adding my story here…When I try following this procedure here, and I get somewhere closer to the goal. When replacing
@nuxtjs/i18nversion8.0.0-beta.12by@nuxtjs/i18n-edgeversion8.0.0-beta.12-28090693.c8406ad, I’m faced with a new error when trying to build:I’ve tried to set it (which requires my prettier config to be renamed to
prettier.config.cjs) and it works 😃 🎉 , but I’d like to avoid having to set"type": "module"in mypackage.jsonfile. 😅EDIT: Renaming the config file was not required - it works for me having the config file named
i18n.config.ts.I am having a different error now:
Hi,
Yes the solution of @gbyesiltas is work but we have
[nuxt] error caught during app initialization ReferenceError: format is not definederror when downgroad to beta-11 ahahahmm 🤔 when we are set
ssr: falseonnuxt.config.ts, we can meet your error.Does putting the package version in edge is a kind of downgrade ? I applied this solution (edge) to solve my build and it worked for me (after rolling my head on the keyboard for an hour). What are the pros and cons ?
Just found out that adding
"type": "module"now is required to use this package 😊 https://github.com/nuxt-modules/i18n/pull/2052 - so it’s working for me 😎👍🎉that didn’t work for me @serdarde =(