dargmuesli / nuxt-cookie-control

A highly configurable cookie banner for Nuxt.
MIT License
241 stars 45 forks source link

$cookies is type of uknown while using i18n micro #235

Closed kleinpetr closed 2 weeks ago

kleinpetr commented 2 weeks ago

Environment


Reproduction

https://stackblitz.com/github/kleinpetr/nuxt-cookies-i18n

run pnpm typecheck

Describe the bug

Once I use i18n micro module https://nuxt.com/modules/nuxt-i18n-micro I am getting a typecheck error under the nuxtApp().$cookies as you can see in the reproduction

'nuxtApp.$cookies' is of type 'unknown'

Additional context

No response

Logs

node_modules/.pnpm/@dargmuesli+nuxt-cookie-control@8.4.13_magicast@0.3.5_rollup@4.24.0_webpack-sources@3.2.3_webpack@5.95.0/node_modules/@dargmuesli/nuxt-cookie-control/dist/runtime/components/CookieControl.vue:310:3 - error TS18046: 'nuxtApp.$cookies' is of type 'unknown'.

310   nuxtApp.$cookies.locale.value = props.locale
      ~~~~~~~~~~~~~~~~

node_modules/.pnpm/@dargmuesli+nuxt-cookie-control@8.4.13_magicast@0.3.5_rollup@4.24.0_webpack-sources@3.2.3_webpack@5.95.0/node_modules/@dargmuesli/nuxt-cookie-control/dist/runtime/components/CookieControl.vue:434:5 - error TS18046: 'nuxtApp.$cookies' is of type 'unknown'.

434     nuxtApp.$cookies.locale.value = locale
        ~~~~~~~~~~~~~~~~

node_modules/.pnpm/@dargmuesli+nuxt-cookie-control@8.4.13_magicast@0.3.5_rollup@4.24.0_webpack-sources@3.2.3_webpack@5.95.0/node_modules/@dargmuesli/nuxt-cookie-control/dist/runtime/components/CookieIframe.vue:36:9 - error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 'Partial<Record<Locale, Partial<LocaleStrings>>>'.

36   () => moduleOptions.localeTexts[nuxtApp.$cookies.locale.value],
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/.pnpm/@dargmuesli+nuxt-cookie-control@8.4.13_magicast@0.3.5_rollup@4.24.0_webpack-sources@3.2.3_webpack@5.95.0/node_modules/@dargmuesli/nuxt-cookie-control/dist/runtime/components/CookieIframe.vue:36:35 - error TS18046: 'nuxtApp.$cookies' is of type 'unknown'.

36   () => moduleOptions.localeTexts[nuxtApp.$cookies.locale.value],
s00d commented 2 weeks ago

When this module is enabled, something strange happens with the router, and the next function disappears from the hook. After checking the source code, it seems that this module doesn’t use router at all. I added a check in my module, and now everything seems to work fine. You can try version 1.21.4.

Honestly, I’m not entirely sure what was wrong, but it looks like I fixed it.

But actually, I had a different error, not with $cookies. Maybe this will help.

I checked it here:

https://stackblitz.com/edit/github-rbx1ec?file=app.vue

It seems to be working.

dargmuesli commented 2 weeks ago

@s00d if you mean this: image

this also happens with // '@dargmuesli/nuxt-cookie-control', (disabled) I think: https://stackblitz.com/edit/github-rbx1ec-rhjgqp?file=nuxt.config.ts

dargmuesli commented 2 weeks ago

You can continue this discussion here or over at https://github.com/s00d/nuxt-i18n-micro/issues/27, I'm just closing this here for now as I don't think it's related to this module. But we can reopen of course if there is anything in need to change on this module's end :raised_hands:

kleinpetr commented 2 weeks ago

When this module is enabled, something strange happens with the router, and the next function disappears from the hook. After checking the source code, it seems that this module doesn’t use router at all. I added a check in my module, and now everything seems to work fine. You can try version 1.21.4.

Honestly, I’m not entirely sure what was wrong, but it looks like I fixed it.

But actually, I had a different error, not with $cookies. Maybe this will help.

I checked it here:

https://stackblitz.com/edit/github-rbx1ec?file=app.vue

It seems to be working.

not sure what you mean by It seems to be working but the pnmp typecheck still not passing :thinking:

s00d commented 2 weeks ago

@s00d if you mean this: image

this also happens with // '@dargmuesli/nuxt-cookie-control', (disabled) I think: https://stackblitz.com/edit/github-rbx1ec-rhjgqp?file=nuxt.config.ts

https://stackblitz.com/edit/github-rbx1ec-fjwgte?file=nuxt.config.ts Just add a pages folder; without it, the routing won’t be generated. I’ll try to fix this later.