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

HMR not working when updating locale files with lazy: true #905

Closed
1 of 2 tasks

Comments

@Akryum
Copy link

Akryum commented Sep 27, 2020

Version

nuxt-i18n: 6.15.1
nuxt: 2.14.6

Nuxt configuration

mode:

  • universal
  • spa

Nuxt-i18n configuration

Reproduction Link

https://github.com/Akryum/nuxt-i18n-hmr

Steps to reproduce

  • Create fresh new Nuxt project
  • Add nuxt-i18n
  • Setup a lazy js locale file
  • Run dev
  • Change locale content

What is Expected?

  • Locale is updated on the client

What is actually happening?

  • Nothing happens after rebuild

Browser console:

client.js?1b93:241 [HMR] bundle rebuilding
client.js?1b93:250 [HMR] bundle 'client' rebuilt in 169ms
process-update.js?e135:51 [HMR] Checking for updates on the server...
process-update.js?e135:123 [HMR] Nothing hot updated.

Workaround

  • Make a full page refresh everytime the locale has changed.
@rchl
Copy link
Collaborator

rchl commented Oct 6, 2020

I'm not sure if there is a way to fix that. I can't see one at least. We'd need to manually trigger re-load of locales on HMR event but I don't see any way to add a hook for that.

@rchl rchl changed the title HMR not working HMR not working when updating locale files with lazy: true Oct 6, 2020
@tvld
Copy link

tvld commented Oct 12, 2020

Have same problem. When I change some locale text in our en.coffee, I see the page regenerating but I need to refresh browser before I see the new changed text. This did worked in one of the previous versions, I am 100% sure: we have been working like this all spring and summer... I do not know exactly what version broke the HMR though...

Related to #807 ?

@rchl
Copy link
Collaborator

rchl commented Oct 12, 2020

There was a change 6.13.3 that made the default locale be loaded from NuxtState to avoid an extra network request on initial load. Could be that that broke HMR.

@tvld
Copy link

tvld commented Oct 12, 2020

Ah, would you know anyway to circumvent this? This issue slows down our coding every day so I would be glad if we can fix this )

@tvld
Copy link

tvld commented Oct 12, 2020

Ok, thank you for the tip... npm remove nuxt-i18n and npm install nuxt-i18n@6.13.2 solved the issue... it is working again :-) )))

@kissu
Copy link

kissu commented Dec 2, 2020

Had this issue too. Hope it gets fixed until then, I found that we can set this kind of configuration.

[
  'nuxt-i18n',
  {
	...
    vuex: {
      moduleName: 'i18n', 
      syncLocale: false, 
      syncMessages: false, 
      syncRouteParams: false, // only this one is mandatory for the configuration actually
    },
  },
],

⚠️ Warning, it will disallow the usage of switchLocalePath. I don't use it so I'm fine. 👍🏻

Thanks to #644 who helped me find this one !

EDIT: nvm, it's still buggy. 😭

@tvld
Copy link

tvld commented Dec 3, 2020

@kissu you need to downgrade as well to make it work?

@kissu
Copy link

kissu commented Dec 3, 2020

@tvld tried your version, wiped my node_modules and cleaned .nuxt before installing this specific version.
Still got the error. Then I tried w/ syncRouteParams: false and now it's working. Didn't get a single error for now.

Didn't thought about it at first, thanks ! 🙏🏻

Do we know where does it come from ?

@kissu
Copy link

kissu commented Dec 3, 2020

Coming for updates: it is not working properly, still the same issue. Gonna remove lazy loading I guess. x)
image

@tvld
Copy link

tvld commented Dec 3, 2020

For what it is worth, I use these settings:

i18n: {
    vueI18n: {
      fallbackLocale: 'en',
      // messages: {
      //   en: require('./assets/lang/en.coffee'),
      //   nl: require('./assets/lang/nl.coffee')
      // },
      silentTranslationWarn: true
    },
    seo: false, // memory leak / performance issue if = true?
    detectBrowserLanguage: {
      useCookie: true,
      cookieKey: 'site_language',
      alwaysRedirect: true,
      fallbackLocale: 'en'
    },
    // loadLanguagesAsync: true,
    defaultLocale: 'en',
    strategy: 'prefix_except_default',
    // parsePages: true
    lazy: true,
    langDir: 'assets/lang/',
    locales: [
      {
        name: 'English',
        code: 'en',
        iso: 'en-US',
        file: 'en.coffee'
      },
      {
        name: 'Nederlands',
        code: 'nl',
        iso: 'nl-NL',
        file: 'nl.coffee'
      }
    ],
    vuex: {
      moduleName: 'my-i18n',
      syncLocale: false,
      syncMessages: false,
      syncRouteParams: true
    }
  },

But I must say for now I use only English, I did not test in quite some time the language switching... )

@stale
Copy link

stale bot commented Feb 2, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 2, 2021
@rchl rchl added pinned 📌 and removed stale labels Feb 2, 2021
@sellou
Copy link

sellou commented Mar 11, 2021

I have the same issue with these packages

"nuxt": "^2.15.2",
"nuxt-i18n": "^6.20.4",
"vue": "^2.6.12",

I tried both the lazy and the non lazy options. Sometimes I need to reload the whole server and sometimes only the page. Did you find any solution ? Thanks

i18n: 
  locales : [
        { code: 'en', iso: 'en-US', file: 'en.js', dir: 'ltr', name: 'English' },
        { code: 'es', iso: 'es-ES', file: 'es.js', dir: 'ltr', name: 'Español' },
        { code: 'fr', iso: 'fr-FR', file: 'fr.js', dir: 'ltr', name: 'Français' },
      ],
      seo                   : true,
      lazy                  : true,
      baseUrl               : 'https://babelglobe.com',
      langDir               : 'assets/locales/',
      defaultLocale         : 'en',
      detectBrowserLanguage : {
        fallbackLocale : 'en',
        onlyOnRoot     : true,
      },
      vueI18n : {
        fallbackLocale : 'en',
        // messages       : { en, es, fr }
      }
}

@rchl
Copy link
Collaborator

rchl commented Mar 15, 2021

This was referenced Mar 16, 2021
@appinteractive
Copy link

@rchl now I get:

Ignored an update to unaccepted module ./lang/en.json -> ./lang lazy recursive ^\.\/.*\.json$ -> ./lang/index.js -> ./plugins/co-co/index.ts -> ./.nuxt/index.js -> ./.nuxt/client.js -> 0
[HMR] The following modules couldn't be hot updated: (Full reload needed)
This is usually because the modules which have changed (and their parents) do not know how to hot reload themselves. See https://webpack.js.org/concepts/hot-module-replacement/ for more details.

@rchl
Copy link
Collaborator

rchl commented Mar 30, 2021

Which nuxt-i18n version exactly? I might have broken it in the today's release but previous should work

@rchl
Copy link
Collaborator

rchl commented Mar 30, 2021

If it's still failing with previous version then you might want to provide reproduction steps

@bahung1221
Copy link

bahung1221 commented Aug 2, 2021

same issue here when using lazy: true, each time I change a text inside a translation file that will cause the app full reload instead of hot reload.

I tried 6.20.6 and ^6.28.0

process-update.js?e135:22 Ignored an update to unaccepted module ./i18n/build/vi.json -> ./.nuxt/nuxt-i18n/options.js -> ./.nuxt/nuxt-i18n/plugin.main.js -> ./.nuxt/index.js -> ./.nuxt/client.js -> 0

I created a new issue: #1252

@nzesalem
Copy link

nzesalem commented Jan 20, 2022

I recently ran into a similar issue... I solved it by simplifying my folder structure.

My folder structure looked something like this;
| project
-| components
- -| Article
- - -| ArticleComponent.vue
- - -| ArticleComponent2.vue
- - -| new
- - - -| NewComponent.vue
- - - -| NewComponent2.vue
-| pages

I changed it to something like;
| project
-| components
- -| Article
- - -| ArticleComponent1.vue
- - -| ArticleComponent2.vue
- -| CreateArticle
- - -| Component1.vue
- - -| Component2.vue
-| pages

And that solved the issue

I wrote about it in detail here 👉: https://vorlume.com/nzesalem/stories/nuxt-file-changes-not-triggering-rebuild-in-nuxt-and-how-i-fixed-it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment