nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.65k stars 465 forks source link

Unexpected token 'pages' #2986

Closed vis97c closed 1 week ago

vis97c commented 1 week ago

Environment

Reproduction

https://stackblitz.com/edit/bobbiegoede-nuxt-i18n-starter-3aas7r?file=pages%2Findex.vue

Describe the bug

Vite HMR fails with the following:

imagen

This is a project wide issue, not sure where the issue is coming from. But in a route if I remove the i18n block from the most inner route the error goes away. I tried to replicate that with no avail.

Doing some debugging I found this:

imagen

Additional context

For context I recently moved my locale from their own *.json file for each page to then import it via custom block src tag. To just include a single i18n block with the translations.

This was the before:

imagen

and imported them like this

imagen

Logs

ERROR  Pre-transform error: Unexpected token 'pages'.            5:57:35 p.m.

ℹ Vite client warmed up in 20187ms                               5:57:47 p.m.
ℹ Vite server warmed up in 23511ms                               5:57:51 p.m.
✔ Nuxt Nitro server built in 15611 ms                      nitro 5:57:52 p.m.

 ERROR  Internal server error: Unexpected token 'pages'.          5:58:11 p.m.
  Plugin: unplugin-vue-i18n
  File: C:/projects/xamu/store/pages/app/[businessSlug]/settings/index.vue?vue&type=i18n&index=0&lang.json
      at ExtendParser.raise (C:\projects\xamu\store\node_modules\jsonc-eslint-parser\lib\parser\extend-parser.js:74:25)
      at ExtendParser.unexpected (C:\projects\xamu\store\node_modules\jsonc-eslint-parser\lib\parser\extend-parser.js:90:22)
      at pp$9.expect (C:\projects\xamu\store\node_modules\acorn\dist\acorn.js:766:28)
      at pp$5.parseObj (C:\projects\xamu\store\node_modules\acorn\dist\acorn.js:3182:14)
      at pp$5.parseExprAtom (C:\projects\xamu\store\node_modules\acorn\dist\acorn.js:2907:19)
      at pp$5.parseExprSubscripts (C:\projects\xamu\store\node_modules\acorn\dist\acorn.js:2715:21)
      at pp$5.parseMaybeUnary (C:\projects\xamu\store\node_modules\acorn\dist\acorn.js:2681:19)
      at pp$5.parseExprOps (C:\projects\xamu\store\node_modules\acorn\dist\acorn.js:2608:21)
      at pp$5.parseMaybeConditional (C:\projects\xamu\store\node_modules\acorn\dist\acorn.js:2591:21)
      at pp$5.parseMaybeAssign (C:\projects\xamu\store\node_modules\acorn\dist\acorn.js:2558:21)

 WARN  [Vue Router warn]: No match found for location with path "/_nuxt/pages/app/[businessSlug]/settings/index.vue?vue&type=i18n&index=0&lang.json"

 WARN  [Vue Router warn]: No match found for location with path "/_nuxt/pages/app/[businessSlug]/settings/index.vue"

 WARN  [Vue Router warn]: No match found for location with path "/_nuxt/pages/app/[businessSlug]/settings/index.vue"

 WARN  [Vue Router warn]: No match found for location with path "/_nuxt/pages/app/[businessSlug]/settings/index.vue"

 WARN  [Vue Router warn]: No match found for location with path "/_nuxt/pages/app/[businessSlug]/settings/index.vue?vue&type=i18n&index=0&lang.json"
vis97c commented 1 week ago

Spotted the source of the issue. Using html as string within the json on the i18n block seems to be breaking the parsing of the block. Removing it solved the issue. Now I'm using a variable to define the html and using the locale where is needed only:

imagen