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

Namespace 'i18next' has no exported member 'TranslationFunction' #295

Open
developer-pta opened this issue Feb 4, 2019 · 14 comments
Open

Comments

@developer-pta
Copy link

I'm submitting a bug report

  • Library Version:
    3.0.0-beta.5

Please tell us about your environment:

  • Operating System:
    Windows [10]

  • Node Version:
    11.8.0

  • NPM Version:
    6.7.0
  • JSPM OR Webpack AND Version
    JSPM 0.16.32 | webpack 2.1.0-beta.17
  • Browser:
    all

  • Language:
    TypeScript 3.1.2

Current behavior:
On 'au build' it throws errors:
error TS2694: Namespace 'i18next' has no exported member 'TranslationFunction'
error TS2694: Namespace 'i18next' has no exported member 'TranslationOptions'

Expected/desired behavior:

  • What is the expected behavior?
    The expected behavior is to successfuly compile.

  • What is the motivation / use case for changing the behavior?

@developer-pta
Copy link
Author

developer-pta commented Feb 4, 2019

Ok, this errors are in module /node_modules/aurelia-i18n/dist/aurelia-i18n.d.ts
and it seems to be related to: i18next/i18next#1180 where they introduced a BREAKING CHANGE i v.14 of i18next.

the breaking change is:

TranslateFunction -> TFunction
TranslateOptions -> TOptions
WithT.t - removed definition and extracted to TFunction
exists - stopped (mis)using TranslateFunction and defined separately
reorder the TFunction args to make easier for typical use (result first)
default TFunction to return string by default. For arrays and objects, parameterize the call e.g. t('foo')

So by renameing those calls in aurelia-i18n.d.ts, should work fine.
Will try then report.

@bigopon
Copy link
Member

bigopon commented Feb 4, 2019

@ProtechAutomation Cool, thanks for the finding. The definition was built with v11 or 12 I think, and newer version of i18next will probably requires some updates from i18next plugin. It should not be difficult to do so though. Would be nice if you could create a PR to fix this

@developer-pta
Copy link
Author

developer-pta commented Feb 4, 2019

@ProtechAutomation Cool, thanks for the finding. The definition was built with v11 or 12 I think, and newer version of i18next will probably requires some updates from i18next plugin. It should not be difficult to do so though. Would be nice if you could create a PR to fix this

Will try. I have never done this (PR).
And yes, the build is passing if i make those changes.

@bigopon
Copy link
Member

bigopon commented Feb 4, 2019

@ProtechAutomation You can follow the instruction for development in README.md, if you hit any issues, please post it here ❤️

@developer-pta
Copy link
Author

Hmm...
It seem that those were not the only changes they made.
This was also changed:

functions used to return a callback (eg. init, changeLanguage, loadNamespaces) now also return a Promise - while this enables easier handling using async await this also means eg. i18next.init does not return this anylonger and therefore you can't chain calls like i18next.init().on() anylonger.

So now i get new problems in:

public async setup(options?: AureliaEnhancedOptions & i18next.InitOptions) {
   const defaultOptions : AureliaEnhancedOptions & i18next.InitOptions = {
     skipTranslationOnMissingKey: false,
     //compatibilityAPI: "v1",
     compatibilityJSON: "v1",
     lng: "en",
     attributes: ["t", "i18n"],
     fallbackLng: "en",
     debug: false
   };
   this.i18nextDeferred = new Promise((resolve, reject) => {
     this.i18next = this.i18next.init(options || defaultOptions, (err) => {
   	if (err) {
   	  reject(err);
   	}
   	// make sure attributes is an array in case a string was provided
   	if (this.i18next.options.attributes instanceof String) {
   	  this.i18next.options.attributes = [this.i18next.options.attributes as any as string];
   	}
   	resolve(this.i18next);
     });
   });
   return this.i18nextDeferred;
}

Where first I had to make the type of defaultOptions explict, and remove 'compatibilityAPI: "v1"'.
Now vscode is complaining of the i18next.init method not returning the correct type. The init method now returns: Promise<i18next.TFunction> while aurelia.i18n expects: public i18next: AureliaEnhancedI18Next;

@developer-pta
Copy link
Author

Ok, I think I found some way to fix this.
Because the 'Init' function no longer return the expected i18Next.i18n type, it can't be use to create new instances. so i find another function that does this and returns the i18Next.i18n type : 'createInstance()'

I replaced the init line with this.i18next.createInstance() like this:

this.i18next = this.i18next.createInstance(options || defaultOptions, (err) => {
    if (err) { 
        reject(err);
    }
     // make sure attributes is an array in case a string was provided
    if (this.i18next.options.attributes instanceof String) { 
        this.i18next.options.attributes = [this.i18next.options.attributes as any as string]; 
    } 
    resolve(this.i18next); 
});

So far VS code does not show any errors in code.
Will try to build and run tests to see if this works.

@developer-pta
Copy link
Author

Ok,

npm run build
...ok

npm run test
...ok

I created a pull request for it: fix-for-295

EisenbergEffect added a commit that referenced this issue Feb 12, 2019
Fix for #295, upgraded i18next to v14.0.1
@mredl
Copy link

mredl commented Mar 20, 2019

Problem still exists. I installed aurelia-i18n yesterday, got 3.0.0-beta.5, and during build i get following 3 errors:
c:/..../node_modules/aurelia-i18n/dist/aurelia-i18n.d.ts(31,45): error TS2694: Namespace 'i18next' has no exported member 'TranslationFunction'.
c:/..../node_modules/aurelia-i18n/dist/aurelia-i18n.d.ts(36,47): error TS2694: Namespace 'i18next' has no exported member 'TranslationOptions'.
c:/..../node_modules/aurelia-i18n/dist/aurelia-i18n.d.ts(173,39): error TS2694: Namespace 'i18next' has no exported member 'TranslationOptions'.

Edit: aurelia-i18n.d.ts still contained old types in this lines. i have changed them to the types of the PR and the build errors have gone away.

@EisenbergEffect
Copy link
Contributor

@zewa666 Any ideas?

@zewa666
Copy link
Member

zewa666 commented Mar 21, 2019

@mredl thats weird, can you check on a fresh new project what gets installed and whether the old types are present in the same d.ts file?

@mredl
Copy link

mredl commented Mar 21, 2019

i did! that was a fresh new project, created with cli on the same day. the first plugin i installed was aurelia-18n.
then i got this ts errors which i have fixed. but the app still hangs during loading of aurelia-18n.
if i uncomment the loading in main.ts the app boots.

Edit: i have tried it now on a different workstation, where no aurelia app has been coded before, there it works without troubles. it looks like npm has pulled some modules from local cache, that an older version of aurelia-i18n or dependency got installed

@zewa666
Copy link
Member

zewa666 commented Mar 25, 2019

@mredl oh wow that was super dumb mistake from our side :( We've forgot to release the latest version on npm and I was merely testing it from a local branch. Sorry for that. @EisenbergEffect can you create another patch release?

@EisenbergEffect
Copy link
Contributor

I'll get a release out tonight 😄

@EisenbergEffect
Copy link
Contributor

@zewa666 I don't think I can release this yet. There seems to still be an issue. In the generated d.ts file for the library, there are two imports for i18next, with two different syntaxes. This makes the d.ts invalid. It also leads me to be believe that one of the imports, which isn't correct, is still used somewhere in the codebase. Can you investigate? You can see the issue if you build master and look at the generated d.ts. Let me know.

zewa666 added a commit that referenced this issue Mar 28, 2019
* use the init method as intended (promise)
* do not reject on 404 errors raised by the backend

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

No branches or pull requests

5 participants