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

[Bug]: MonoRepo (turborepo) + nuxt and shared packages/ui folder not working

Open orenmizr opened this issue 4 months ago • 1 comments

Reproduction

too complex

Describe the bug

original shadcn ui monorepo solution: https://ui.shadcn.com/docs/monorepo

shadcn-nuxt fails to properly handle component directories located in workspace packages within a monorepo setup, causing ENOTDIR errors and import failures when trying to use shared UI components across multiple apps.

Environment

  • shadcn-nuxt version: 2.1.0
  • Nuxt version: 3.17.4
  • Package manager: pnpm with workspaces
  • Monorepo tool: Turborepo
  • shadcn-vue components: Using Vue port of shadcn/ui

Project Structure

project/ ├── apps/ │ ├── web/ # Nuxt 3 app │ │ ├── nuxt.config.ts │ │ ├── components.json │ │ └── package.json │ └── extension/ # WXT browser extension (non-Nuxt) ├── packages/ │ └── ui/ # Shared shadcn-vue components │ ├── src/ │ │ ├── index.ts # Export barrel │ │ ├── button/ │ │ ├── drawer/ │ │ └── ... (other components) │ └── package.json ├── package.json # Root workspace config └── pnpm-workspace.yaml

Relevant Configuration Files

packages/ui/package.json: { "name": "@project/ui", "main": "./src/index.ts", "exports": { ".": "./src/index.ts" } }

apps/web/nuxt.config.ts (attempted configuration): export default defineNuxtConfig({ modules: ["shadcn-nuxt"], shadcn: { componentDir: fileURLToPath(new URL('../../packages/ui/src', import.meta.url)), prefix: "", }, components: [ '~/components', { path: fileURLToPath(new URL('../../packages/ui/src', import.meta.url)), pathPrefix: false, extensions: ['.vue'], pattern: ['**/*.vue'], ignore: ['index.ts', 'utils.ts'] } ] })

Steps to Reproduce

  1. Create a monorepo with pnpm workspaces
  2. Set up a shared UI package with shadcn-vue components
  3. Configure shadcn-nuxt to point componentDir to the workspace package
  4. Try to use components in the Nuxt app
  5. Run pnpm dev

Expected Behavior

  • shadcn-nuxt should properly resolve components from workspace packages
  • Components should be auto-imported without manual import statements
  • No scanning or module resolution errors

Actual Behavior

Issues Encountered

  1. ENOTDIR Errors: Nuxt tries to scan index.ts as a directory
  2. Import Resolution Failures: Components from workspace packages fail to resolve
  3. Auto-import Conflicts: Nuxt's component auto-import doesn't work with workspace paths
  4. Cross-framework Limitations: Solution needs to work with both Nuxt apps and non-Nuxt consumers

Root Cause Analysis

  1. shadcn-nuxt assumes local component directory: The module is designed for components located within the same app, not external workspace packages
  2. Nuxt component scanning issues: The auto-import system doesn't properly handle TypeScript barrel exports in workspace packages
  3. File vs Directory confusion: index.ts files are being treated as directories by the scanner

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    Memory: 5.08 GB / 15.49 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 22.14.0 - ~/.local/share/pnpm/node
    npm: 10.9.2 - ~/.local/share/pnpm/npm
    pnpm: 10.12.3 - ~/.local/share/pnpm/pnpm
  Browsers:
    Chrome: 138.0.7204.92

Contributes

  • [x] I am willing to submit a PR to fix this issue
  • [ ] I am willing to submit a PR with failing tests

orenmizr avatar Jul 01 '25 14:07 orenmizr