shadcn-vue icon indicating copy to clipboard operation
shadcn-vue copied to clipboard

[Bug]: In a javascript nuxt project the components are created outside of the project root folder

Open hubcio2115 opened this issue 1 year ago • 19 comments

Environment

Developement/Production OS: macOS 14.2.1
Node version: 20.9.0
Package manager: [email protected]
Radix Vue version: 1.3.2
Shadcn Nuxt version: 0.8.7
Vue version: 3.4.14
Nuxt version: 3.9.3
Nuxt mode: universal
Nuxt target: server
CSS framework: @nuxtjs/[email protected]
Client OS: macOS 14.2.1

Link to minimal reproduction

https://github.com/hubcio2115/shadcn-nuxt-minimal-reproduction

Steps to reproduce

Run

npx shadcn-vue@latest init

Describe the bug

In a fresh javascript nuxt project with default configuration folders for lib and components get created outside of the project folder. Any subsequent runs of shadcn-vue add also put components outside of the project folder.

Everything works fine in a typescript project.

Expected behavior

components and lib are added to the project and components added through cli add are also put where they suppose to be as per the shadcn configuration.

Conext & Screenshots (if applicable)

image

hubcio2115 avatar Jan 18 '24 10:01 hubcio2115

https://stackblitz.com/edit/github-3ryei7

Add this to your nuxt.config.js/ts even if you are JS

export default defineNuxtConfig({
  typescript: {
    tsConfig: {
      compilerOptions: {
        baseUrl: '.'
      }
    }
  }
})

That's strange 😕

With tsconfig.json CLI is working as expected without "baseUrl": "." in ./.nuxt/tsconfig.json

But with jsconfig.json, "baseUrl": "." must be exist in ./.nuxt/tsconfig.json

sadeghbarati avatar Jan 20 '24 06:01 sadeghbarati

Oh, yeah that works but when I put it in jsconfig.json instead of nuxt.config it still bugs out. So the issue remains.

hubcio2115 avatar Jan 21 '24 16:01 hubcio2115

@Dunqing Can you also check this?

It's not related to detypes error in the carousel, calendar, vue-sonner components.

I explained it above

sadeghbarati avatar Jan 29 '24 16:01 sadeghbarati

I will take a look soon.

Dunqing avatar Jan 30 '24 02:01 Dunqing

I had the following problem during the init phase : npx shadcn-vue@latest init

✔ Would you like to use TypeScript (recommended)? … no
✔ Which framework are you using? › Nuxt
✔ Which style would you like to use? › Default
✔ Which color would you like to use as base color? › Slate
✔ Where is your global CSS file? … assets/main.css
✔ Would you like to use CSS variables for colors? … no
✔ Where is your tailwind.config located? … tailwind.config.js
✔ Configure the import alias for components: … @/components
✔ Configure the import alias for utils: … @/lib/utils
✔ Write configuration to components.json. Proceed? … yes

✔ Writing components.json...
ENOENT: no such file or directory, stat '/jsconfig.json'

I able to solve this problem by having the following jsconfig.json file in my project root before calling

{
  // https://nuxt.com/docs/guide/concepts/typescript
  "$schema": "https://json.schemastore.org/jsconfig.json",
  "extends": "./.nuxt/tsconfig.json",
  "compilerOptions": {
    "baseUrl": ".",
  }
}

In the initial instructions I skipped this step, because I have a js project. : image

I believe that skipping this step causes the project to not have a config file.

I would add in a solution for js projects to the documentation.

However even though the init shows successful, as pointed out here the components and lib directory are created outside of project root.

I followed @sadeghbarati suggestion of adding this to nuxt.config.ts but it didnt work.

AdamBD avatar Feb 09 '24 21:02 AdamBD

Anyone working on this?

AdamBD avatar Apr 16 '24 19:04 AdamBD

I'm encountering the same issues as @AdamBD and @hubcio2115

RamaHerbin avatar Apr 17 '24 15:04 RamaHerbin

I had no issues following the CLI suggestions:

❯ npx shadcn-vue@latest init
✔ Would you like to use TypeScript? (recommended)? … no / yes
✔ Which framework are you using? › Nuxt
✔ Which style would you like to use? › Default
✔ Which color would you like to use as base color? › Slate
✔ Where is your tsconfig.json file? … .nuxt/tsconfig.json
✔ Where is your global CSS file? (this file will be overwritten) … assets/css/tailwind.css
✔ Would you like to use CSS variables for colors? … no / yes
✔ Where is your tailwind.config located? (this file will be overwritten) … tailwind.config.js
✔ Configure the import alias for components: … @/components
✔ Configure the import alias for utils: … @/lib/utils
✔ Write configuration to components.json. Proceed? … yes

Following the suggestions in the documentation item 7, the components are created outside of the project root folder:

image

educbraga avatar May 27 '24 03:05 educbraga

This fixed iit for me

npx [email protected] add tabs

sugoidesune avatar May 27 '24 06:05 sugoidesune

I have Nuxt/TS project and this change in components.json fixed it for me. "tsConfigPath": "tsconfig.json" -> "tsConfigPath": "./.nuxt/tsconfig.json",

gormal avatar May 31 '24 13:05 gormal

This fixed iit for me

npx [email protected] add tabs

how does this help with the components and lib directories being created outside of project root?

AdamBD avatar Jun 04 '24 06:06 AdamBD

I have Nuxt/TS project and this change in components.json fixed it for me. "tsConfigPath": "tsconfig.json" -> "tsConfigPath": "./.nuxt/tsconfig.json",

this bug is related to JS installations, not TS

AdamBD avatar Jun 04 '24 06:06 AdamBD

This fixed iit for me

npx [email protected] add tabs

how does this help with the components and lib directories being created outside of project root?

Because the bug was introduced with [email protected] so using [email protected] works.

sugoidesune avatar Jun 05 '24 13:06 sugoidesune

this bug is related to JS installations, not TS

Definitely also exists in TS with [email protected]

sugoidesune avatar Jun 05 '24 13:06 sugoidesune

I have Nuxt/TS project and this change in components.json fixed it for me. "tsConfigPath": "tsconfig.json" -> "tsConfigPath": "./.nuxt/tsconfig.json",

yep this fixed it for me whe using nuxt, I guess during the init steps you need to point inside of the .nuxt folder instead of the root tsconfig

nulfrost avatar Aug 03 '24 03:08 nulfrost

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  modules: ['@nuxtjs/tailwindcss', 'shadcn-nuxt'],
  shadcn: {
    /**
     * Prefix for all the imported component
     */
    prefix: '',
    /**
     * Directory that the component lives in.
     * @default "./components/ui"
     */
    componentDir: './components/ui'
  },
  typescript: {
    tsConfig: {
      compilerOptions: {
        baseUrl: '.'
      }
    }
  }
})

Then npx shadcn-vue@latest init

image

Erel0 avatar Aug 30 '24 18:08 Erel0

I found that the component has just loaded to /.nuxt/components/ui/ so you've just copied and pasted it in the right path.

ThamNithi avatar Sep 01 '24 07:09 ThamNithi

@zernonia Please fix this

murshex avatar Oct 01 '24 13:10 murshex

Still persists. However this in fact fixed it for me, so thank you @gormal :

I have Nuxt/TS project and this change in components.json fixed it for me. "tsConfigPath": "tsconfig.json" -> "tsConfigPath": "./.nuxt/tsconfig.json",

lukaspodmelle avatar Oct 04 '24 13:10 lukaspodmelle

I have Nuxt/TS project and this change in components.json fixed it for me. "tsConfigPath": "tsconfig.json" -> "tsConfigPath": "./.nuxt/tsconfig.json",

Hey I've used this fix but this adds a folder named "*" everytime

realcryptopunk avatar Oct 26 '24 09:10 realcryptopunk