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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

21.5.1 problem with default export (TypeScript) #1692

Closed
rvanmil opened this issue Nov 16, 2021 · 8 comments
Closed

21.5.1 problem with default export (TypeScript) #1692

rvanmil opened this issue Nov 16, 2021 · 8 comments

Comments

@rvanmil
Copy link

@rvanmil rvanmil commented Nov 16, 2021

馃悰 Bug Report

The following code used to work without eslint complaining:

import i18n from 'i18next'
i18n.t('foobar')

After 21.5.1 this results in the message: Caution: i18n also has a named export t. Check if you meant to write import {t} from 'i18next' instead. import/no-named-as-default-member

Changing the code to:

import { t } from 'i18next'
t('foobar')

Results in a syntax error: Module '"i18next"' has no exported member 't'. Did you mean to use 'import t from "i18next"' instead?ts(2614)

Changing the code to:

import { default as i18n } from 'i18next'
i18n.t('foobar')

Fixes the problem, but I don't think it's supposed to work this way.

To Reproduce

https://codesandbox.io/s/i18next-typescript-import-issue-r2huh?file=/src/App.tsx

Your Environment

  • runtime version: react-scripts 4.0.3, react 17.0.2, typescript 4.4.4
  • i18next version: 21.5.1
  • os: Browser
@adrai
Copy link
Member

@adrai adrai commented Nov 16, 2021

Can you retry with v21.5.2 ?

@adrai
Copy link
Member

@adrai adrai commented Nov 16, 2021

@rvanmil
Copy link
Author

@rvanmil rvanmil commented Nov 16, 2021

Can you retry with v21.5.2 ?

Thanks, this fixes import { t } from 'i18next'. But it did not fix the eslint warning when using import i18n from 'i18next'. Edit: nevermind the warning is correct now because the named export is available obviously :)

@adrai
Copy link
Member

@adrai adrai commented Nov 16, 2021

Can you retry with v21.5.2 ?

But it did not fix the eslint warning when using import i18n from 'i18next'.

I'm not seeing any warning here: https://codesandbox.io/s/i18next-typescript-import-issue-r2huh?file=/src/App.tsx
image
I'm not a TypeScript user so can you advice on how I should see that warning?
Is it possible this is a local problem on your setup?

@rvanmil
Copy link
Author

@rvanmil rvanmil commented Nov 16, 2021

I don't think it's possible to reproduce that on codesandbox, afaik it doesn't support custom eslint configs. You could try locally with this config:

"eslintConfig": {
  "extends": [
    "react-app",
    "prettier",
    "plugin:import/recommended",
    "plugin:import/typescript"
  ]
}

(the rule import/no-named-as-default-member should be set to warn)

@adrai
Copy link
Member

@adrai adrai commented Nov 16, 2021

ahhh if import/no-named-as-default-member is enabled, the warning makes sense.
So there's probably nothing we can do here.

@rvanmil
Copy link
Author

@rvanmil rvanmil commented Nov 16, 2021

Yeah the issue is resolved, thanks 馃槉馃憤

@adrai
Copy link
Member

@adrai adrai commented Nov 16, 2021

If you like this module don鈥檛 forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project.

There are many ways to help this project 馃檹

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

No branches or pull requests

2 participants