Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing i18n options file with npm run generate #1990

Closed
WolfgangDrescher opened this issue Apr 13, 2023 · 29 comments · Fixed by #2025 or #2199
Closed

Missing i18n options file with npm run generate #1990

WolfgangDrescher opened this issue Apr 13, 2023 · 29 comments · Fixed by #2025 or #2199
Assignees
Labels
config need reproduction 💻 ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf v8

Comments

@WolfgangDrescher
Copy link

Environment

  • Operating System: Linux
  • Node Version: v16.14.2
  • Nuxt Version: 3.4.1
  • Nitro Version: 2.3.3
  • Package Manager: [email protected]
  • Builder: vite
  • User Config: modules, i18n
  • Runtime Modules: @nuxtjs/[email protected]
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-6ylvpz

run npm i && npm run generate && serve .output/public

Describe the bug

When the nuxt project is built with npm run generate the generated build will crash and throw error 500 with error message format is not defined. When you check the network tab in the developer tools you will see that the i18n-config-[hash].js file will not exist status 404 is returned.

Bildschirmfoto 2023-04-13 um 16 07 18

Additional context

No response

Logs

No response

@WolfgangDrescher
Copy link
Author

When you try to build with the old syntax

export default defineNuxtConfig({
    i18n: {
        strategy: 'prefix_except_default',
        locales: [
            { code: 'de', iso: 'de-DE', file: 'de.yaml', dir: 'ltr' },
            { code: 'en', iso: 'en-US', file: 'en.yaml', dir: 'ltr' },
        ],
        defaultLocale: 'de',
        langDir: 'locales/',
        vueI18n: {
            fallbackLocale: 'de',
            legacy: false,
            locale: 'de',
        },
    },
});

the console will output:

ERROR  [@nuxtjs/i18n]: The vueI18n option is no longer be specified with object.
It must be specified in the configuration file via the 'i18n.config' path.
About deprecated reason, see https://v8.i18n.nuxtjs.org/guide/migrating#change-the-route-key-rules-in-pages-option
About new configuration style, sqee https://v8.i18n.nuxtjs.org/getting-started/basic-usage#translate-with-vue-i18n

However, i18n.config doesn't seem to exist in the module options, or am I wrong?

i18n/src/types.ts

Lines 53 to 88 in a0ead8d

export type NuxtI18nOptions<Context = unknown> = {
vueI18n?: string
experimental?: ExperimentalFeatures
precompile?: LocaleMessagePrecompileOptions
differentDomains?: boolean
detectBrowserLanguage?: DetectBrowserLanguageOptions | false
langDir?: string | null
lazy?: boolean
pages?: CustomRoutePages
customRoutes?: 'page' | 'config'
/**
* @internal
*/
i18nModules?: { langDir?: string | null; locales?: I18nRoutingOptions<Context>['locales'] }[]
/**
* @deprecated `'parsePages' option is deprecated. Please use 'customRoutes' option instead. We will remove it in v8 official release.`
*/
parsePages?: boolean
rootRedirect?: string | null | RootRedirectOptions
routesNameSeparator?: string
skipSettingLocaleOnNavigate?: boolean
strategy?: Strategies
types?: 'composition' | 'legacy'
debug?: boolean
dynamicRouteParams?: boolean
} & Pick<
I18nRoutingOptions<Context>,
| 'baseUrl'
| 'strategy'
| 'defaultDirection'
| 'defaultLocale'
| 'defaultLocaleRouteNameSuffix'
| 'locales'
| 'routesNameSeparator'
| 'trailingSlash'
>

A clarification of the correct usage in the documentation would be useful.

Copy link
Collaborator

kazupon commented Apr 13, 2023

It must be specified in the configuration file via the 'i18n.config' path.

Sorry, This error message is wrong.
That message mean that we need to specify like i18n.config path to the vueI18n option.

@kazupon kazupon added good first issue 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing PR Welcome and removed pending triage labels Apr 13, 2023 — with Volta.net
@elzodxon
Copy link

How can we resolve it?

Copy link
Collaborator

kazupon commented Apr 14, 2023

The vueI18n option can no longer be specified with object. Instead, you must specify a configuration file such as i18n.config.ts and specify the path to that configuration file in the vueI18n option.

you can see the docs:

@WolfgangDrescher
Copy link
Author

Still there seems to be a problem with nuxt generate. The config file does not end up in the build. Please check the reproduction instructions. However, I also noticed that with nuxt build there was also a 404 client side for this file. But the website did not crash. It looks like resolving this server side works fine, but there is something wrong client side.

@edoecohen
Copy link

This is also happening to me when I try to deploy to Vercel.

When I run nuxt build locally, the .nuxt/i18n folder and the config file aren't automatically generated until I refresh my browser.

Here is my .nuxt folder after running nuxt build:
image

And here it is again after I run the build server using node .output/server/index.mjs and refreshing localhost:
image

But in Vercel it just crashes beforehand since it can't find the config file:
image

@kazupon kazupon added ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf and removed PR Welcome 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing good first issue labels Apr 16, 2023 — with Volta.net
@kkuepper
Copy link

We have the same problem. It seems to be new in beta11 since beta10 doesn't have that problem (However it has another problem).

@awacode21
Copy link

Bildschirm­foto 2023-04-23 um 12 57 27

i think i have the same or a related error.

When building locally, everything is fine, but building on vercel ends up with a blank page throwing that error on console

@hansemannn
Copy link
Contributor

Workaround: Roll back to v8.0.0-beta.10 (which requires to revert the config file change to an object notation). Once it's fixed, the config file can be used again.

Copy link
Collaborator

kazupon commented Apr 23, 2023

I’m working on this issue.

The reason is taking a little time is because our main day job DEADLINE, is coming up at the end of this month.

Please assured that this issue is not being ignored at all and wait. 🙏

@kovai
Copy link

kovai commented Apr 26, 2023

This is also happening to me when I try to deploy to Vercel.

When I run nuxt build locally, the .nuxt/i18n folder and the config file aren't automatically generated until I refresh my browser.

Here is my .nuxt folder after running nuxt build: image

And here it is again after I run the build server using node .output/server/index.mjs and refreshing localhost: image

But in Vercel it just crashes beforehand since it can't find the config file: image

I had the same problem.
The secret is very simple. It was the file system permissions to write files to .nuxt directory, because the file .nuxt/i18n/config-cfcb45fa.js was created after running node .output/server/index.mjs.
And simply fixed by adding file write permissions to the .nuxt directory for the node process.

@jekuer
Copy link

jekuer commented Apr 26, 2023

Still should be seen as a workaround. Default should run out of the box without messing with those rights (imho).

@urielb
Copy link

urielb commented May 4, 2023

I had this exact issue when trying to deploy the result of the "npm run generate" command.

Everything worked great on development, but after deploying the application to my production server, only an error 500 page with the message "format is not defined" would show up.

In a previous comment on this thread I saw someone talking about a missing file log on the console, and when I decided to look it up on my deploy, I've noticed that the file it was missing was in a path that wasn't supposed to exist, so it is missing from the generated files.

It turns out that the i18n.options.js file was pointing to an invalid i18n.config.js file. In my case it was like this:

import{_ as s,J as i}from"./entry.db7f202a.js";async function c(n){const e=await s(()=>import("./i18n.config.ec968ab2.js"),[],import.meta.url).then(t=>t.default||t),o=i.isFunction(e)?await e(n):i.isObject(e)?e:{};{let t=null;try{const a="/i18n-config-aabec199.js";t=await s(()=>import(a),[],import.meta.url).then(r=>r.default||r)}catch(a){console.error(format(a.message))}return o.messages=t||{},o}}export{c as default};

Manually modifying the file to look like this solved the issue for me:
import { _ as s, J as i } from "./entry.db7f202a.js"; async function c(n) { const e = await s(() => import("./i18n.config.ec968ab2.js"), [], import.meta.url).then(t => t.default || t), o = i.isFunction(e) ? await e(n) : i.isObject(e) ? e : {}; { let t = null; try { const a = "/_nuxt/i18n.config.ec968ab2.js"; t = await s(() => import(a), [], import.meta.url).then(r => r.default || r) } catch (a) { console.error(format(a.message)) } return o.messages = t || {}, o } } export { c as default };

After I've fixed the link to the i18n.config file, everything started working as expected.

@edoecohen
Copy link

I’m working on this issue.

The reason is taking a little time is because our main day job DEADLINE, is coming up at the end of this month.

Please assured that this issue is not being ignored at all and wait. 🙏

@kazupon any update on the fix? or ETA? thanks!

@kazupon kazupon self-assigned this May 8, 2023
@kazupon kazupon reopened this May 8, 2023
Copy link
Collaborator

kazupon commented May 8, 2023

I've fixed this issue.
Please check edge channel 8.0.0-beta.11-28059008.d1499b6 version.
Thanks!

@Rakantor
Copy link

Rakantor commented May 8, 2023

I've fixed this issue. Please check edge channel 8.0.0-beta.11-28059008.d1499b6 version. Thanks!

I'm getting a different error now when I try to build the project with npx nuxi generate:

[4:42:41 PM]  ERROR  [nuxtjs:i18n-resource-dynamic] Plugin error - Unable to get file name for unknown file "6b5f3ecd".
[4:42:41 PM] ℹ ✓ built in 12ms
[4:42:41 PM]  ERROR  Plugin error - Unable to get file name for unknown file "6b5f3ecd".
  at error (node_modules/rollup/dist/es/shared/node-entry.js:2125:30)
  at FileEmitter.getFileName (node_modules/rollup/dist/es/shared/node-entry.js:24128:24)
  at node_modules/@nuxtjs/i18n/dist/module.mjs:1216:50
  at Array.reduce (<anonymous>)
  at Object.generateBundle (node_modules/@nuxtjs/i18n/dist/module.mjs:1215:44)
  at node_modules/rollup/dist/es/shared/node-entry.js:24551:40
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

@awacode21
Copy link

awacode21 commented May 8, 2023

The workaround of downgrading to v8.0.0-beta.10 does not work for me. It ends up in all nuxt-link not working. Need to downgrade. to v8.0.0-beta.9

@edoecohen
Copy link

I've fixed this issue. Please check edge channel 8.0.0-beta.11-28059008.d1499b6 version. Thanks!

@kazupon I updated to edge channel 8.0.0-beta.11-28059008.d1499b6 version.
The .nuxt/i18n folder and the config file are indeed now generated during nuxt build and was able to deploy on Vercel.
But am also seeing some new errors that weren't there before.

Copy link
Collaborator

kazupon commented May 9, 2023

But am also seeing some new errors that weren't there before.

Could you give us your errors? 🙏

@jekuer
Copy link

jekuer commented May 12, 2023

With latest beta12, I get another error than before too.
See below:

ERROR  [nuxtjs:i18n-resource-dynamic] Plugin error - Unable to get file name for unknown file "2fbc62cc".                                                                                                                                                                 20:41:56  

ℹ ✓ built in 32ms                                                                                                                                                                                                                                                          20:41:56  

 ERROR  Plugin error - Unable to get file name for unknown file "2fbc62cc".                                                                                                                                                                                                20:41:56  

  at error (/C:/Users/XYZ/node_modules/rollup/dist/es/shared/node-entry.js:2125:30)
  at FileEmitter.getFileName (/C:/Users/XYZ/node_modules/rollup/dist/es/shared/node-entry.js:24128:24)
  at /C:/Users/XYZ/node_modules/@nuxtjs/i18n/dist/module.mjs:1216:50
  at Array.reduce (<anonymous>)
  at Object.generateBundle (/C:/Users/XYZ/node_modules/@nuxtjs/i18n/dist/module.mjs:1215:44)
  at /C:/Users/XYZ/node_modules/rollup/dist/es/shared/node-entry.js:24551:40
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

And only if I have the following in my nuxt.config.ts:
vueI18n: './vue-i18n.options.ts',

@tlebeitsuk
Copy link

I'm getting the same error as @jekuer using nuxt generate.

Copy link
Collaborator

kazupon commented May 15, 2023

Please reproduction repo or stackbliz 🙏

@Rakantor
Copy link

Please reproduction repo or stackbliz 🙏

See here: https://stackblitz.com/edit/github-cr1uk5-mr8fcr?file=package.json
Thanks!

@kazupon
Copy link
Collaborator

kazupon commented May 16, 2023

like the similar issue #2077
#1990 (comment)

@ZacxDev
Copy link

ZacxDev commented May 21, 2023

I am also facing this issue with the latest beta version (12)
Here is the relevant logs from my vercel deployment:

@nuxtjs/i18n Cannot find module '/var/public/__i18n__/prerender/924d8e8b.js' imported from /var/task/chunks/app/_nuxt/i18n.options-3b873373.mjs

Copy link
Collaborator

kazupon commented May 24, 2023

@Rakantor
Sorry for my late replay.
Your reproduction is same as #2029

I fixed it with #2099, so You can try edge change version.

@Rakantor
Copy link

@kazupon
I can confirm that #2099 fixed the issue on my end and I was able to deploy my project to GitHub Pages.
Thanks for all the hard work!

@WolfgangDrescher
Copy link
Author

When using 8.0.0-beta.12-28113576.7bc33c3 I am still experiencing the same problems as @ZacxDev in #1990 (comment).

I updated the reproduction repo: https://stackblitz.com/edit/github-6ylvpz-ezzvf7

Everything works fine in development mode but when you run npm i && npm run generate && serve .output/public in the demo repo you will get (only relevant part copied):

ℹ Prerendering 4 initial routes with crawler                                    nitro 12:32:44
  ├─ / (69ms)                                                                   nitro 12:32:44
  ├─ /200.html (1ms)                                                            nitro 12:32:44
  ├─ /404.html (0ms)                                                            nitro 12:32:44

[12:32:44]  ERROR  (node:26) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use node --trace-warnings ... to show where the warning was created)


 ERROR  [nuxt] [request error] [unhandled] [500] Unexpected token 'export'            12:32:44
  at Object.compileFunction …

  ├─ /__i18n__/prerender/3e10f522.js (24ms) (Error: [500] )                     nitro 12:32:44
  ├─ /_payload.js (0ms)                                                         nitro 12:32:44
✔ You can now deploy .output/public to any static hosting!                            12:32:44

You will get the same result while building when you run npm i && npm run build && node .output/server/index.mjs and an additional error when you access the page:

@nuxtjs/i18n Cannot find module '/home/projects/github-6ylvpz-ezzvf7/.output/public/__i18n__/prerender/3e10f522.js' imported from /home/projects/github-6ylvpz-ezzvf7/.output/server/chunks/app/_nuxt/i18n.options-6a54e9dc.mjs

@FreekVR
Copy link

FreekVR commented Jun 21, 2023

Getting similar errors unfortunately, on beta 12 when deployed to Vercel

@nuxtjs/i18n Cannot find module '/var/public/__i18n__/prerender/cfcb45fa.js' imported from /var/task/chunks/app/_nuxt/i18n.options-4604e0f1.mjs

When the page is pre-rendered it doesn't seem to happen - but it does error when it's not and the page is rendered through nuxt SSR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config need reproduction 💻 ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf v8
Projects
None yet