Romanchuk / angular-i18next

angular v10+ integration with i18next v19.4+
MIT License
131 stars 33 forks source link

Fresh installation - Version Mismatch | require is not defined #91

Closed medansolutions closed 1 year ago

medansolutions commented 1 year ago

Installing library on fresh angular projects gives error that latest version of i18next (v22 is not supported) and that I need to have version. This one seems like an easy fix - just configuration in package.json of the library: "i18next": ">=19.5.4 <22.0.0",

Second problem I can't really figure out, when launching fresh project with installed i18next (v21) and angular-i18next (v14.1) compilation completes successfully - however when opening in browser, I get error in console:

Uncaught ReferenceError: require is not defined

I've checked in my node modules and that require function is really there instead of 'normal' browser import.

Any suggestiosn/workaround for this issue?

Node version 18 (also tested with 16, same issue) Angular version 14

Hopefully this is issue just for me, and is not making library unusable for other people.

Forcing to version 11 of the library seems to work as intended.

Romanchuk commented 1 year ago

I need to checkout i18next migration guides for v22 before raise version. Wait for it or override dep at your own risk: https://stackoverflow.com/a/48524488/2208167

Ok, i'll see what's with installation

Romanchuk commented 1 year ago

Also, you can try v14.0.5

medansolutions commented 1 year ago

I tried with version 14.0.5 works properly. :)

From what I can see, breaking code was introduced in I18NextService.ts where

const i18next = i18n.default;

was swapped with

const i18next = require('i18next');
Romanchuk commented 1 year ago

@medansolutions about v22 - they changed typings a bit. And some types are not exported... but exists. So, it takes time to adjust my code to new typings. But i18next declares that v22 totally compatible with v21, so you can use it.

Yes, it's broken line. I'll release beta

Romanchuk commented 1 year ago

I've created an issue in official repo: https://github.com/i18next/i18next/issues/1869

Romanchuk commented 1 year ago

@medansolutions Please try v14.2.0-0

Romanchuk commented 1 year ago

@medansolutions Oh, sorry missed one place 14.2.0-1

Romanchuk commented 1 year ago

@medansolutions Stable version 14.2.0 released! 'require' problem fixed Still waiting i18next types to be fixed to support v22

medansolutions commented 1 year ago

Hi, compilation seems to work properly now - however, I need to disable strictNullChecks in my tsconfig.json in order for application to compile. Not sure if this is library or typings issue. But IMO should be added to readme file atleast.

Error: node_modules/angular-i18next/lib/I18NextEvents.d.ts:5:5 - error TS2416: Property 'initialized' in type 'I18NextEvents' is not assignable to the same property in base type 'ITranslationEvents'.
  Type 'BehaviorSubject<InitOptions>' is not assignable to type 'BehaviorSubject<InitOptions | undefined>'.
    Types of property 'observers' are incompatible.
      Type 'Observer<InitOptions>[]' is not assignable to type 'Observer<InitOptions | undefined>[]'.
        Type 'Observer<InitOptions>' is not assignable to type 'Observer<InitOptions | undefined>'.
          Type 'InitOptions | undefined' is not assignable to type 'InitOptions'.
            Type 'undefined' is not assignable to type 'InitOptions'.

5     initialized: BehaviorSubject<i18n.InitOptions>;
      ~~~~~~~~~~~

Error: node_modules/angular-i18next/lib/I18NextEvents.d.ts:11:5 - error TS2416: Property 'languageChanged' in type 'I18NextEvents' is not assignable to the same property in base type 'ITranslationEvents'.
  Type 'BehaviorSubject<string>' is not assignable to type 'BehaviorSubject<string | null>'.
    Types of property 'observers' are incompatible.
      Type 'Observer<string>[]' is not assignable to type 'Observer<string | null>[]'.
        Type 'Observer<string>' is not assignable to type 'Observer<string | null>'.
          Type 'string | null' is not assignable to type 'string'.
            Type 'null' is not assignable to type 'string'.

11     languageChanged: BehaviorSubject<string>;

However, issue I initially reported is now solved. Thank you!

Romanchuk commented 1 year ago

@medansolutions Yeap, work will be in #97