i18next / i18next-xhr-backend

[deprecated] can be replaced with i18next-http-backend
https://github.com/i18next/i18next-http-backend
MIT License
253 stars 75 forks source link

After migration to `3.2.0` import does not work anymore #327

Closed scharf closed 4 years ago

scharf commented 4 years ago

I migrated form 2.0.1 to 3.2.0. With 2.0.1 the import code (from TypeScript on the client) looked like:

import XHR from 'i18next-xhr-backend';

After updating to 3.2.0 the value of XHR is now undefined.

This import does not work either:

import { XHR } from 'i18next-xhr-backend';

And the following import throws an error.

import * as XHR from 'i18next-xhr-backend';

So, I am pretty clueless, how to import the module...

scharf commented 4 years ago

The only way I could get it to work is

// @ts-ignore
import XHR = require('i18next-xhr-backend/dist/cjs/i18nextXHRBackend.js');
jamuhl commented 4 years ago

@rosskevin sorry, to having bother you with all the typescript issues...but can't make any sense out of this...

rosskevin commented 4 years ago

Our ts usage test (not runtime test) proves a typical default import works: https://github.com/i18next/i18next-xhr-backend/blob/master/test/typescript/i18next-xhr-backend.ts#L1

The runtime code also shows a default export.

If you are having to do something different with imports, I assume you are doing something to cause this with your tsconfig. Checking the one here, we are not turning on synthetic or esModuleInterop, so it would seem nothing special is needed and I don't know how to guide you here.

rosskevin commented 4 years ago

BTW, if you are new and just getting started:

allowSyntheticDefaults: true esModuleInterop: true

Is going to save you headaches with imports.

scharf commented 4 years ago

I did not know about those options. I added the option to my project (which broke a few other imports that I fixed) and now it words.

But there seems no way to use XHR in TypeScript unless you set "esModuleInterop": true in tsconfig.json, or am I missing something here?

rosskevin commented 4 years ago

That should not be true, but you can definitely misconfigure tsconfig to make it incompatible.

scharf commented 4 years ago

but you can definitely misconfigure tsconfig to make it incompatible.

using the defaults is misconfiguring?

rosskevin commented 4 years ago

No, defaults should work fine - as they are tested here - they work. See the tsconfig in this repo, but you can change module, target, typeroots, includes, etc in incompatible ways.