nx-extend
nx-extend copied to clipboard
Wrong import when adding component. - Shadcn Plugin
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.
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.
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"
}
}
That looks good, the tsconfig in the root also has the paths correctly defined?
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"
]
}
I have the exact same problem. Tried on a fresh install. It always imports from @projectname/lib/utils.
Even when I change the aliases in components.json, it has no effect (and yes, I delete the .nx cache after making manual changes)
Same issue here.