Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Typescript module resolution problem when importing from library's subpath without extension #18288

Closed
7 tasks done
croraf opened this issue Oct 5, 2024 · 0 comments
Closed
7 tasks done

Comments

@croraf
Copy link

croraf commented Oct 5, 2024

Describe the bug

The application has a default Vite - ts+react template configuration. I try to reference modules from my custom library which has in package.json

  "exports": {
    ".": {
      "import": "./index.ts"
    },
    "./lib/*": {
      "import": "./lib/*"
    }
  }

In the application I try to import the modules:

import Test from '@inxelo/components/lib/AutocompleteLargeDataset2.tsx'
import Test2 from '@inxelo/components/lib/AutocompleteLargeDataset2' // <--- this errors out

The import without extension errors out.

Cannot find module '@inxelo/components/lib/AutocompleteLargeDataset2' or its corresponding type declarations.ts(2307)

If in tsconfig I change moduleResolution: "node" it doesn't error out.

Runtime works fine (in the example it does not work cause it needs additional setup in the code, but in my production it works fine in runtime).

Reproduction

https://github.com/croraf/typescript-import-issue

Steps to reproduce

No response

System Info

System:
    OS: Linux 6.5 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 26.16 GB / 31.21 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.20.4 - ~/.nvm/versions/node/v18.20.4/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v18.20.4/bin/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v18.20.4/bin/npm
  Browsers:
    Chrome: 129.0.6668.70
    Chromium: 129.0.6668.89
  npmPackages:
    @vitejs/plugin-react: ^4.3.2 => 4.3.2 
    vite: ^5.4.8 => 5.4.8

Used Package Manager

yarn

Logs

No response

Validations

@vitejs vitejs locked and limited conversation to collaborators Oct 6, 2024
@hi-ogawa hi-ogawa converted this issue into discussion #18290 Oct 6, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

1 participant