Skip to content

Broken imports from @uidotdev/usehooks after upgrading to v3.9.0 or later #448

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Brandon-Ritchie opened this issue May 14, 2025 · 9 comments
Assignees
Labels

Comments

@Brandon-Ritchie
Copy link

Brandon-Ritchie commented May 14, 2025

Upgrading from version 3.8.3 to 4.3.4 and I am getting errors that there are pretty much no exports availaboe from @uidotdev/usehooks.

The breaking change seems to be with version 3.9.0, when there was a migration between resolvers.

Here is my tsconfig (if that is helpful):

{
    "compilerOptions": {
        "target": "ES2020",
        "useDefineForClassFields": true,
        "lib": ["ES2020", "DOM", "DOM.Iterable"],
        "module": "ESNext",
        "skipLibCheck": true,

        /* Bundler mode */
        "moduleResolution": "bundler",
        "allowImportingTsExtensions": true,
        "resolveJsonModule": true,
        "isolatedModules": true,
        "noEmit": true,
        "jsx": "react-jsx",

        /* Linting */
        "strict": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "noFallthroughCasesInSwitch": true
    },
    "include": ["src"],
    "references": [{ "path": "./tsconfig.node.json" }]
}

And here is the relevant part of my eslint config:

import importPlugin from "eslint-plugin-import";

...
{
    ...

    importPlugin.flatConfigs.recommended,
    {
        rules: {
            "import/first": "error",
            "import/no-amd": "error",
            "import/no-anonymous-default-export": "error",
        },
        settings: {
            "import/parsers": {
                "@typescript-eslint/parser": [".ts", ".tsx"],
            },
            "import/resolver": {
                typescript: {
                    alwaysTryTypes: true,
                    project: "./tsconfig.json"
                },
            },
        },
    },

    ...
}
@Brandon-Ritchie Brandon-Ritchie changed the title Unable to import from @uidotdev/usehooks after v3.9.0 Unable to import from @uidotdev/usehooks after upgrading to v3.9.0 or later May 14, 2025
@Brandon-Ritchie Brandon-Ritchie changed the title Unable to import from @uidotdev/usehooks after upgrading to v3.9.0 or later Broken imports from @uidotdev/usehooks after upgrading to v3.9.0 or later May 14, 2025
@JounQin
Copy link
Collaborator

JounQin commented May 14, 2025

Please provide a minimal but runnable reproduction.

@Brandon-Ritchie
Copy link
Author

@JounQin here is a repository that shows the issue: https://github.com/Brandon-Ritchie/eslint-import-reproduction

@JounQin
Copy link
Collaborator

JounQin commented May 15, 2025

I seems to be related to unnecessary declare module "@uidotdev/usehooks" block in node_modules/@uidotdev/usehooks/index.d.ts, if you remove that, there will be no issue. I believe it's not related to this resolver, but of course it could be improved in eslint-plugin-import's side.

For eslint-import-resolver-typescript <3.9.0, it works because it fails to resolve types for @uidotdev/usehooks and then just fallback to index.js instead.

Image
  eslint-import-resolver-typescript looking for @uidotdev/usehooks in /workspace/eslint-import-reproduction/src/useUIDotDev.ts +38ms
  eslint-import-resolver-typescript looking for @types/uidotdev__usehooks in /workspace/eslint-import-reproduction/src/useUIDotDev.ts +3ms
  eslint-import-resolver-typescript failed to resolve with @types/uidotdev__usehooks +2ms
  eslint-import-resolver-typescript didn't find  @types/uidotdev__usehooks +0ms
  eslint-import-resolver-typescript matched node path: /workspace/eslint-import-reproduction/node_modules/@uidotdev/usehooks/index.js +0ms

By the way, I'd suggest you to migrate to https://github.com/un-ts/eslint-plugin-import-x instead, see also un-ts/eslint-plugin-import-x#323 for more details. I'd like to transfer this issue to eslint-plugin-import-x instead because we could improve the parser to understand declare module "@uidotdev/usehooks", but we're in different organizations, would you mind close this one and raise it to eslint-plugin-import or eslint-plugin-import-x instead?

@Brandon-Ritchie
Copy link
Author

Closing to open in eslint-plugin-import.

@Brandon-Ritchie
Copy link
Author

Re-opening until I am able to confirm that I posted in the correct place.

@ljharb
Copy link
Member

ljharb commented May 15, 2025

If there's an issue with TS resolution I'm not sure how it can be improved on the plugin side.

@JounQin
Copy link
Collaborator

JounQin commented May 15, 2025

If there's an issue with TS resolution I'm not sure how it can be improved on the plugin side.

@ljharb It's not about the resolution, but parsing .d.ts and recognize declare module 'xx' block.

@ljharb
Copy link
Member

ljharb commented May 15, 2025

That's definitely something outside the purview of the plugin - it'd need to be in something TS-specific.

@JounQin
Copy link
Collaborator

JounQin commented May 15, 2025

@Brandon-Ritchie Let's close this issue then, I believe @ljharb agrees that we could improve how we handle this TypeScript case now: import-js/eslint-plugin-import#3186 (comment).

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

No branches or pull requests

3 participants