For my current project, I am utilizing TypeScript and i18next for internalization.
TypeScript version: 2.1.4
i18next version: 2.3.4
@types/i18next version: 2.3.35
In the specific file:
import * as i18next from 'i18next';
i18next.init({
lng: 'en',
resources: {
en: {
translation: {
"key": "hello world"
}
}
}
}, (err, t) => {
// Initialization complete!
const hw = i18next.t('key'); // hw = 'hello world'
});
However, when inspecting in the browser, an error message is displayed:
Uncaught TypeError: i18next.init is not a function
If I log the i18next object, it displays like this:
https://i.sstatic.net/FfsVZ.png
And in the console, calling i18n.default.init
works fine.
When importing as such:
import i18next from 'i18next';
Visual Studio Code will raise a complaint: https://i.sstatic.net/3BXCa.png
My .tsconfig file looks like this:
{
"compileOnSave": true,
"compilerOptions": {
"removeComments": false,
"baseUrl": "./src",
"target": "es6",
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noImplicitAny": true,
"strictNullChecks": true,
"jsx": "preserve",
"lib": [
"es2017",
"dom"
],
"typeRoots": [
"./node_modules/@types"
],
"types": [
"node",
"poly2tri",
"three",
"i18next"
]
}
}
Unfortunately, my webpack.config.js file is too lengthy to include here.
I'm curious if there is any connection to this document: http://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-class-d-ts.html
/*~ Note that ES6 modules cannot directly export class objects.
*~ This file should be imported using the CommonJS-style:
*~ import x = require('someLibrary');
*~
*~ Refer to the documentation to understand common
*~ workarounds for this limitation of ES6 modules.
*/