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

Bad template generation with i18n module #135

Open
skmd87 opened this issue Jan 15, 2024 · 8 comments · May be fixed by #148
Open

Bad template generation with i18n module #135

skmd87 opened this issue Jan 15, 2024 · 8 comments · May be fixed by #148
Labels
bug Something isn't working

Comments

@skmd87
Copy link

skmd87 commented Jan 15, 2024

Describe the bug
Nuxt won't start when i18n is enabled. the following errors printed in console:

 ERROR(vue-tsc)  ';' expected.
 FILE  C:/www/nuxt3-boilerplate/.nuxt/typed-router/__paths.d.ts:23:8

    21 |
    22 |
  > 23 |   type ValidStringPath<T> = T extends ${string} ${string} ? false : T extends '' ? false : true;
       |        ^^^^^^^^^^^^^^^
    24 |
    25 |   type ValidParam<T, R extends boolean = true> = T extends ${infer A}/${infer B}
    26 |   ? A extends ${string} ${string}

 ERROR(vue-tsc)  ';' expected.
 FILE  C:/www/nuxt3-boilerplate/.nuxt/typed-router/__paths.d.ts:23:31

    21 |
    22 |
  > 23 |   type ValidStringPath<T> = T extends ${string} ${string} ? false : T extends '' ? false : true;
       |                               ^^^^^^^
    24 |
    25 |   type ValidParam<T, R extends boolean = true> = T extends ${infer A}/${infer B}
    26 |   ? A extends ${string} ${string}

 ERROR(vue-tsc)  ';' expected.
 FILE  C:/www/nuxt3-boilerplate/.nuxt/typed-router/__paths.d.ts:23:73

    21 |
    22 |
  > 23 |   type ValidStringPath<T> = T extends ${string} ${string} ? false : T extends '' ? false : true;
       |                                                                         ^^^^^^^
    24 |
    25 |   type ValidParam<T, R extends boolean = true> = T extends ${infer A}/${infer B}
    26 |   ? A extends ${string} ${string}

 ERROR(vue-tsc)  Type expected.
 FILE  C:/www/nuxt3-boilerplate/.nuxt/typed-router/__paths.d.ts:91:13

    89 |       ? T extends '/'
    90 |         ? "index"
  > 91 |          :  : never
       |             ^
    92 |        : never;
    93 |
    94 |

 ERROR(vue-tsc)  Declaration or statement expected.
 FILE  C:/www/nuxt3-boilerplate/.nuxt/typed-router/__paths.d.ts:92:8

    90 |         ? "index"
    91 |          :  : never
  > 92 |        : never;
       |        ^
    93 |
    94 |
    95 |

 ERROR(vue-tsc)  ';' expected.
 FILE  C:/www/nuxt3-boilerplate/.nuxt/typed-router/__routes.ts:27:10

    25 |    *
    26 |    * */
  > 27 |   export type RoutesParamsRecord = {
       |          ^^^^
    28 |
    29 |   }
    30 |

 ERROR(vue-tsc)  ';' expected.
 FILE  C:/www/nuxt3-boilerplate/.nuxt/typed-router/__routes.ts:54:10

    52 |    * By default the params are unknown
    53 |    * */
  > 54 |   export type RoutesNamedLocationsResolved =
       |          ^^^^
    55 |   {
    56 |     name: RoutesNamesList;
    57 |     params: unknown;

 ERROR(vue-tsc)  Function type notation must be parenthesized when used in an intersection type.
 FILE  C:/www/nuxt3-boilerplate/.nuxt/typed-router/__routes.ts:58:6

    56 |     name: RoutesNamesList;
    57 |     params: unknown;
  > 58 |   } & (
       |      ^^
  > 59 |
       | ^^^^
  > 60 |       )
       | ^^^^
  > 61 |
       | ^^^^
  > 62 |
       | ^^^^
  > 63 |     export type RoutesNamesListRecord = {};
       | ^^^^^^^^^^^
    64 |
    65 |     export const routesNames = {};
    66 |

 ERROR(vue-tsc)  '=>' expected.
 FILE  C:/www/nuxt3-boilerplate/.nuxt/typed-router/__routes.ts:63:5

    61 |
    62 |
  > 63 |     export type RoutesNamesListRecord = {};
       |     ^^^^^^
    64 |
    65 |     export const routesNames = {};
    66 |

 ERROR(vue-tsc)  ';' expected.
 FILE  C:/www/nuxt3-boilerplate/.nuxt/typed-router/__routes.ts:63:12

    61 |
    62 |
  > 63 |     export type RoutesNamesListRecord = {};
       |            ^^^^
    64 |
    65 |     export const routesNames = {};
    66 |

[vue-tsc] Found 10 errors. Watching for file changes.

Expected behavior
to run nuxt normally

Screenshots
upon checking the generated .ts files, found those problems:
__paths d ts-1
__paths d ts-2
__routes d ts-1
__routes d ts-2

Environnement infos

Your pages folder structure

pages
├── admin
│ └── index.vue
└── index.vue

Your nuxt.config.ts

modules: [
'@pinia/nuxt',
['@nuxtjs/eslint-module', eslintConfig],
['@nuxtjs/i18n', i18nConfig],
'@formkit/auto-animate',
'@vueuse/nuxt',
['@nuxt/image', imageConfig],
['nuxt-simple-sitemap', sitemapConfig],
['nuxt-jsonld', jsonldConfig],
['nuxt-simple-robots', robotsConfig],
'nuxt-typed-router',
['@vite-pwa/nuxt', pwaConfig],
],

//i18n config
import { type ModuleOptions } from '@nuxtjs/i18n'

const config: ModuleOptions = {
defaultLocale: 'en-US',
langDir: 'config/i18n/locales/',
locales: [
{
code: 'en',
iso: 'en-US',
file: 'en-US.json',
},
{
code: 'ar',
iso: 'ar-JO',
file: 'ar-JO.json',
},
],
lazy: true,
strategy: 'prefix'
}

export default config

@victorgarciaesgi
Copy link
Owner

Hi! Yeah there is a problem I spotted with the "prefix" strategy i'm sorry for this. I'll have to refactor a significant part of stuff on 4.0 and it's already in progress

@victorgarciaesgi victorgarciaesgi added the bug Something isn't working label Jan 15, 2024
@skmd87
Copy link
Author

skmd87 commented Jan 16, 2024

looks promsing, is there any beta version yet?

@victorgarciaesgi
Copy link
Owner

Not yet it's not usable, i'll tell you when it's ready. But i'll surely will change how i18n types will work

@mseeley
Copy link

mseeley commented Mar 13, 2024

I'm also running into the same error. Error is different but still traces to strategy: 'prefix' and nuxt-typed-router.

$ pnpm nuxi prepare

 ERROR  Declaration or statement expected. (158:8)                                                                                                                                                     8:46:52 PM
  156 |         ? "index"
  157 |          : any : never
> 158 |        : never;
      |        ^
  159 |
  160 |
  161 |

    156 |         ? "index"
    157 |          : any : never
  > 158 |        : never;
        |        ^
    159 |
    160 |
    161 |

@mseeley
Copy link

mseeley commented Mar 13, 2024

What is the roadmap for this module when contrasted with Nuxt's experimental integration of unplugin-vue-router?

@danwithabox
Copy link

I second that question.
For people ending up here thinking they'd have to use this module to get typed routes, I have successfully started using the experimental.typedPages option with i18n.

To me, that option seems to be the canonic approach, even if it's marked as experimental.

@skmd87
Copy link
Author

skmd87 commented Jun 26, 2024

I second that question. For people ending up here thinking they'd have to use this module to get typed routes, I have successfully started using the experimental.typedPages option with i18n.

To me, that option seems to be the canonic approach, even if it's marked as experimental.

How did you enable i18n tying with experimental.typedPages ??

@danwithabox
Copy link

I second that question. For people ending up here thinking they'd have to use this module to get typed routes, I have successfully started using the experimental.typedPages option with i18n.
To me, that option seems to be the canonic approach, even if it's marked as experimental.

How did you enable i18n tying with experimental.typedPages ??

I just enabled the option, and the linked documentation describes what effect it had:
https://nuxt.com/docs/guide/going-further/experimental-features#typedpages

(...) this will enable typed usage of navigateTo, , router.push() and more

For other i18n typing support, you have to look elsewhere. I personally found the i18n module's typing support to be lackluster in general, but specifically for links, this experimental option worked well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants