React-i18next: VS Code Auto-Import Command attempts to import /* of package.

Created on 25 Feb 2021  路  5Comments  路  Source: i18next/react-i18next

馃悰 Bug Report

Visual Studio Code attempts to import react-i18next as react-i18next/* when attempting to use a function.
As example here:
image
which does not work and causes this error in the end.
image

Removing the extra /* works.

To Reproduce

  1. Install VSCode.
  2. Open a project in VSCode.
  3. npm i react-i18next
  4. Try to use a function for react-i18next.
  5. Use VSCode import / CTRL+. keystroak
  6. See that vscode is attemtping to import react-i18next/*
import { useTranslation } from "react-i18next/*";

const { t } = useTranslation();

Expected behavior

To import the correct path.

import { useTranslation } from "react-i18next";

const { t }聽= useTranslation();

Attempted "Fixes"

1.
https://github.com/i18next/react-i18next/blob/086246ee653b1ff7679a12dbb6b840c23f22fa0b/package.json#L7-L13
To change to:

"typesVersions": {
  ">=4.1": {
    "*": [
      "src/ts4.1/*"
    ]
  }
},

Would fix vscode to import the correct path, but then react refuses to compile cause it can't find module.

2.
Drag items out of the ./src directory in node_modules/react-i18next/ to it's package root.
Edit package json from:

https://github.com/i18next/react-i18next/blob/086246ee653b1ff7679a12dbb6b840c23f22fa0b/package.json#L6-L13
to

"types": "./index.d.ts",
"typesVersions": {
  ">=4.1": {
    "*": [
      "ts4.1/*"
    ]
  }
},

This is what seemed to have 'fixed' it up for me.

Your Environment

  • runtime version: v15.8.0
  • i18next version: 19.8.4
  • react-i18next version: 11.8.8
  • os: Linux
typescript

All 5 comments

I have the same issue.

Thanks @ThomasAunvik, I'll be investigating it

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Hey @ThomasAunvik, TypeScript should allow our current structure, so I opened an issue for it. In the meantime, I'll open a PR to move the type definitions.

Hey @ThomasAunvik, it should be fixed by now. I'll revisit this issue again once the TypeScript team solves the issue above. Thanks for pointing that out!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dawsbot picture dawsbot  路  4Comments

whtsky picture whtsky  路  4Comments

Jessidhia picture Jessidhia  路  4Comments

leandrocamacho picture leandrocamacho  路  4Comments

martinlaregina picture martinlaregina  路  3Comments