Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

VSCode: auto import not working #13

Closed
dhmoon91 opened this issue Sep 26, 2023 · 7 comments
Closed

VSCode: auto import not working #13

dhmoon91 opened this issue Sep 26, 2023 · 7 comments

Comments

@dhmoon91
Copy link

Hi - I was looking for way to easily integrate shdcn with turbo and ran by your repo.

Looks like auto import from vscode isn't working to reference the @ui.

Also how would I import my own components under components/?

eg:

apps/
packages/
  ui/
    components
      /ui
        Button.tsx
      MyComp1.tsx
  MyComp2.tsx

How could I import MyComp1.tsx or MyComp2.tsx? Looks like nextjs.json for tsconfig is set to alias ../../packages/ui/components/ui/*

@hasanaktas
Copy link

Did you find any solution? It is annoying to write each import manually.

@Mill1995
Copy link

Mill1995 commented Oct 19, 2023

@dhmoon91

apps/web
packages/ 
  ui/
    components
      /ui
        Button.tsx
      MyComp1.tsx
  MyComp2.tsx

I was able to do this by configuring the tsconfig.json inside the apps/web tsconfig, by setting these values:

 "paths": {
      "@/*": ["./*"],
      "@ui/*": ["../../packages/ui/*"],
      "@ui/components/ui/*": ["../../packages/ui/components/ui/*"]
    },

With the settings above your import statements should resolve to the correct path alias:

import { MyComp1 } from "@ui/components/ui/Button"

or

import { MyComp2 } from "@ui/components/MyComp2"

@dan5py
Copy link
Owner

dan5py commented Dec 5, 2023

@dhmoon91 if you the import to behave like that you need to edit your tsconfig/nextjs.json, like this:

"paths": {
      "@/*": ["./*"],
      "@ui/*": ["../../packages/ui/*"],
-     "@ui/components/*": ["../../packages/ui/components/ui/*"],
      "@ui/components/ui/*": ["../../packages/ui/components/ui/*"]
    }

You should be able to import all your components.
Regarding the VSCode auto-import, I'm still working on a fix.

@dan5py
Copy link
Owner

dan5py commented Jan 24, 2024

This should be fixed with the new release 1.1.0 (2bc1a8c)

@dan5py dan5py closed this as completed Jan 24, 2024
@RudiPersson
Copy link

I am using 1.1.0. An the vscode autoimport is still not working for me.

@dan5py
Copy link
Owner

dan5py commented Apr 3, 2024

Hi @RudiPersson, could you please try this #17 (comment)

@dan5py dan5py reopened this Apr 3, 2024
@RudiPersson
Copy link

@dan5py this fixed it for me :). Thanks for making this 👏

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants