Skip to content
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

Wrong import when adding component. - Shadcn Plugin #352

Open
RestfuI opened this issue Dec 29, 2024 · 4 comments
Open

Wrong import when adding component. - Shadcn Plugin #352

RestfuI opened this issue Dec 29, 2024 · 4 comments

Comments

@RestfuI
Copy link

RestfuI commented Dec 29, 2024

When running the command nx add-component shadcn-ui button, no errors are displayed; however, the generated import for the cn function in the component is incorrect.

Generated Button.tsx:

import * as React from "react";
import { Slot } from "@radix-ui/react-slot";
import { cva, type VariantProps } from "class-variance-authority";

import { cn } from "@myproject-mono/lib/utils";

...

Expected Import:

import { cn } from "@myproject-mono/shadcn-ui-utils";

Note: The library names provided during plugin usage were shadcn-ui and shadcn-ui-utils.

@TriPSs
Copy link
Owner

TriPSs commented Dec 29, 2024

Those are based off what is defined inside the components.json, could you share that? When the CLI changed that file needed to be updated.

@RestfuI
Copy link
Author

RestfuI commented Dec 29, 2024

Hi,

Thanks for the reply!

Here is my components.json file.

{
  "$schema": "https://ui.shadcn.com/schema.json",
  "style": "default",
  "rsc": false,
  "tailwind": {
    "config": "libs\\shadcn-ui-utils\\src\\tailwind.config.ts",
    "css": "libs\\shadcn-ui-utils\\src\\global.css",
    "baseColor": "neutral",
    "cssVariables": true
  },
  "aliases": {
    "ui": "@myproject-mono/shadcn-ui",
    "components": "@myproject-mono/shadcn-ui/components",
    "utils": "@myproject-mono/shadcn-ui-utils",
    "hooks": "@myproject-mono/shadcn-ui/hooks"
  }
}

@TriPSs
Copy link
Owner

TriPSs commented Dec 30, 2024

That looks good, the tsconfig in the root also has the paths correctly defined?

@RestfuI
Copy link
Author

RestfuI commented Dec 30, 2024

All looks to be correctly configured on my end.

tsconfig.base.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "strictPropertyInitialization": false,
    "importHelpers": true,
    "target": "es2015",
    "module": "esnext",
    "lib": [
      "es2020",
      "dom"
    ],
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "baseUrl": ".",
    "paths": {
      "@myproject-mono/common": [
        "libs/common/src/index.ts"
      ],
      "@myproject-mono/common/api": [
        "libs/common/src/lib/api/index.ts"
      ],
      "@myproject-mono/common/entities": [
        "libs/common/src/lib/entities/index.ts"
      ],
      "@myproject-mono/common/modules": [
        "libs/common/src/lib/modules/index.ts"
      ],
      "@myproject-mono/common/services": [
        "libs/common/src/lib/services/index.ts"
      ],
      "@myproject-mono/shadcn-ui": [
        "libs/shadcn-ui/src"
      ],
      "@myproject-mono/shadcn-ui-utils": [
        "libs/shadcn-ui-utils/src"
      ],
      "@myproject-mono/shadcn-ui/*": [
        "libs/shadcn-ui/src/*"
      ],
      "@myproject-mono/shadcn-ui-utils/*": [
        "libs/shadcn-ui-utils/src/*"
      ]
    }
  },
  "exclude": [
    "node_modules",
    "tmp"
  ]
}

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

No branches or pull requests

2 participants