i18n icon indicating copy to clipboard operation
i18n copied to clipboard

Namespace 'i18next' has no exported member 'TranslationFunction'

Open developer-pta opened this issue 6 years ago • 14 comments

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 avatar Feb 04 '19 09:02 developer-pta

Ok, this errors are in module /node_modules/aurelia-i18n/dist/aurelia-i18n.d.ts and it seems to be related to: https://github.com/i18next/i18next/pull/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.

developer-pta avatar Feb 04 '19 09:02 developer-pta

@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

bigopon avatar Feb 04 '19 09:02 bigopon

@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.

developer-pta avatar Feb 04 '19 09:02 developer-pta

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

bigopon avatar Feb 04 '19 09:02 bigopon

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 avatar Feb 04 '19 11:02 developer-pta

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 avatar Feb 05 '19 09:02 developer-pta

Ok,

npm run build ...ok

npm run test ...ok

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

developer-pta avatar Feb 05 '19 10:02 developer-pta

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.

mredl avatar Mar 20 '19 18:03 mredl

@zewa666 Any ideas?

EisenbergEffect avatar Mar 20 '19 23:03 EisenbergEffect

@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?

zewa666 avatar Mar 21 '19 08:03 zewa666

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

mredl avatar Mar 21 '19 08:03 mredl

@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?

zewa666 avatar Mar 25 '19 06:03 zewa666

I'll get a release out tonight 😄

EisenbergEffect avatar Mar 25 '19 16:03 EisenbergEffect

@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.

EisenbergEffect avatar Mar 26 '19 01:03 EisenbergEffect