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

i18n breaks Nuxt Auto-Import functionality! #2483

Closed
Bombastickj opened this issue Oct 9, 2023 · 21 comments · Fixed by intlify/vue-i18n#1628
Closed

i18n breaks Nuxt Auto-Import functionality! #2483

Bombastickj opened this issue Oct 9, 2023 · 21 comments · Fixed by intlify/vue-i18n#1628

Comments

@Bombastickj
Copy link

Environment

Nuxt project info:


  • Operating System: Windows_NT
  • Node Version: v20.6.1
  • Nuxt Version: 3.7.4
  • CLI Version: 3.9.0
  • Nitro Version: 2.6.3
  • Package Manager: [email protected]
  • Builder: -
  • User Config: devtools, typescript, imports, modules, pinia, i18n
  • Runtime Modules: @pinia/[email protected], @nuxtjs/[email protected]
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/nuxt-starter-cmht5h?file=stores%2Fpage.ts

Describe the bug

The error occurs when using the pinia & i18n packages for nuxt 3. All auto-imports for components are lost, when importing a component inside a pinia store, to define a InstanceType. I've tested to remove the i18n package and all auto-imports were back to normal.

Additional context

Also checked that Volar (takeover) is active. Bug can be viewed easily when following small instructions inside /stores/page.ts

Logs

No response

Copy link
Collaborator

kazupon commented Oct 11, 2023

Thank you for you reporting!

Hmm, 🤔
nuxt i18n is just implemented using addImports.
We’re implementing it using the API provided by nuxt/kit.

i18n/src/module.ts

Lines 297 to 315 in 8a33fec

await addImports([
{ name: 'useI18n', from: vueI18nPath },
...[
'useRouteBaseName',
'useLocalePath',
'useLocaleRoute',
'useSwitchLocalePath',
'useLocaleHead',
'useBrowserLocale',
'useCookieLocale',
NUXT_I18N_COMPOSABLE_DEFINE_ROUTE,
NUXT_I18N_COMPOSABLE_DEFINE_LOCALE,
NUXT_I18N_COMPOSABLE_DEFINE_CONFIG
].map(key => ({
name: key,
as: key,
from: resolve(runtimeDir, 'composables')
}))
])

I don't see why combining it with @pinia/nuxt would cause issues. /cc @posva

@danielroe
Is there anything in nuxt i18n's auto-import implementation that is not within the guidelines?

@posva
Copy link

posva commented Oct 11, 2023

I have no idea why combining both modules would break auto imports 😅

@BobbieGoede
Copy link
Collaborator

After trying the reproduction in stackblitz and locally, I can't reproduce the issue described.

Uninstalling and removing @nuxtjs/i18n and its configuration seems to have no effect, SomePopup gets inferred correctly in app.vue but cannot be found inside the page.ts store with the popupDefined line uncommented. Edited reproduction here

Maybe I'm doing something wrong, can someone else confirm this issue is happening as described?

@Bombastickj
Copy link
Author

Bombastickj commented Oct 11, 2023

After trying the reproduction in stackblitz and locally, I can't reproduce the issue described.

Uninstalling and removing @nuxtjs/i18n and its configuration seems to have no effect, SomePopup gets inferred correctly in app.vue but cannot be found inside the page.ts store with the popupDefined line uncommented. Edited reproduction here

Maybe I'm doing something wrong, can someone else confirm this issue is happening as described?

Yeah to use the InstanceType, you have to uncomment the import in line 9 inside 'page.ts'. Then it will break locally. Mabe the Component needs to be imported another way? My problem is, that it fully works when i18n is not installed..

@BobbieGoede
Copy link
Collaborator

Ah I misread the instructions and didn't see the import on line 9 had to be uncommented as well!

Hmmm, after playing around some more, I noticed that removing imports from nuxt.config.ts seems to make it work as expected.

But after trying more things I noticed that it also works while keeping the imports config, and restarting Volar. Not sure why that is..

Screen.Recording.2023-10-11.at.11.24.35.mov

@danielroe
Copy link
Contributor

I can't reproduce when downloading that stackblitz and refreshing lockfile.

CleanShot 2023-10-11 at 11 06 01

@Bombastickj
Copy link
Author

I can't reproduce when downloading that stackblitz and refreshing lockfile.

CleanShot 2023-10-11 at 11 06 01

Its all fine inside the store. What's not working is the auto-import inside all other files like app.vue when popupDefined is uncommented all components become the type 'unknown'

@github-actions
Copy link

Would you be able to provide a reproduction? 🙏

More info

Why do I need to provide a reproduction?

Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making.

What will happen?

If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritise it based on its severity and how many people we think it might affect.

If needs reproduction labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it.

How can I create a reproduction?

We have a couple of templates for starting with a minimal reproduction:

👉 Reproduction starter (v8 and higher)
👉 Reproduction starter (edge)

A public GitHub repository is also perfect. 👌

Please ensure that the reproduction is as minimal as possible. See more details in our guide.

You might also find these other articles interesting and/or helpful:

@Bombastickj
Copy link
Author

Bombastickj commented Oct 22, 2023

Hi guys, I have some videos to visualize the bug that is happening.

After looking more into it, I've found out that the bug does not only happen inside a pinia store:

i18n_added.mp4

When @nuxt/i18n is removed no bug appears:

i18n_removed.mp4

Updated reproduction:
https://stackblitz.com/edit/nuxt-starter-cmht5h?file=stores%2Fpage.ts

Hope this helps with clarification @kazupon

@Applelo
Copy link

Applelo commented Oct 23, 2023

Hi all, I can confirm @Bombastickj reproduction, I have the same issue with my current project using nuxt i18n last version. All Vue components (from /components folder or coming from other plugins/modules) inside my template are reported as unknow.
[EDIT] What is weird, the components are imported correctly when call inside another components (inside the components folder) but not inside the /pages folder.

@jensk
Copy link

jensk commented Oct 24, 2023

I also can confirm this issue

@BobbieGoede BobbieGoede self-assigned this Oct 25, 2023
@metkm
Copy link

metkm commented Oct 27, 2023

[EDIT] What is weird, the components are imported correctly when call inside another components (inside the components folder) but not inside the /pages folde

This doesn't work for me at all. All the autocompletion just dies even inside the components folder.

@Bombastickj
Copy link
Author

Hello,
do you guys have any updates on why this is happening? @kazupon @BobbieGoede

@BobbieGoede
Copy link
Collaborator

I'm still looking into what the exact source of this issue is, it's not that easy to debug unfortunately.

I have been trying to find what is breaking the type inference by removing type imports inside .nuxt and restarting the vue language server, which is tedious.

By doing so I have been able to narrow it down to types provided by @intlify/vue-i18n-bridge (in vue-i18n-routing) and vue-i18n (in @nuxtjs/i18n), if I remove type imports from those dependencies the type inference seems to work again. Next I will have to figure out what is different about those types, that will take some more time 😭

@kazupon
Copy link
Collaborator

kazupon commented Nov 2, 2023

@BobbieGoede
I reproduced it in my environment. I really appreciate your efforts.

@BobbieGoede
Copy link
Collaborator

It seems like these lines are breaking the type inference https://github.com/intlify/vue-i18n-next/blob/master/packages/vue-i18n/src/vue.d.ts#L1232-L1239

@Bombastickj
Copy link
Author

Thank you so much @BobbieGoede!

@rchl
Copy link
Collaborator

rchl commented Nov 3, 2023

It seems like these lines are breaking the type inference intlify/vue-i18n-next@master/packages/vue-i18n/src/vue.d.ts#L1232-L1239

I haven't looked myself but in that case the issue is likely that it extends GlobalComponents in @vue/runtime-core but should be extending it in vue module instead.

And also it should likely first import 'vue' as the original module needs to be referenced first, otherwise (depending on loading order) the i18n module can overwrite the module instead of extending it.

@kazupon
Copy link
Collaborator

kazupon commented Nov 4, 2023

And also it should likely first import 'vue' as the original module needs to be referenced first, otherwise (depending on loading order) the i18n module can overwrite the module instead of extending it.

The types provided by vue-i18n in npm will be combined with typescript-generated types and vue-extended types defined in src/vue.d.ts when building.
The combined types have import vue, so your point should not be a problem.

@metkm
Copy link

metkm commented Nov 4, 2023

#2490 (comment) This is related. Probably can be closed now if the issue is fixed

@Bombastickj
Copy link
Author

Hi guys!
After having some small issues with opting into the edge release channel, I finally got it working! If anyone runs into some trouble installing, I used node 18.18.2. Don't forget to remove lock file and node_modules before installing.

Thank you guys so much!! @BobbieGoede @kazupon

Fixed reproduction

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

Successfully merging a pull request may close this issue.

9 participants