Nneji123 / fastapi-nextjs

This project demonstrates the integration of FastAPI, SQLModel, PostgreSQL, Redis, Next.js, Docker, and Docker Compose, showcasing essential API features like rate limiting, pagination, logging, and metrics using Prometheus and Grafana.
MIT License
18 stars 3 forks source link

Frontend Missing Lib\utils.ts #3

Open MetaNets369 opened 3 months ago

MetaNets369 commented 3 months ago

Issue Description

The Frontend app is missing frontend/src/lib/utils.ts

The utils serves as import for button.tsx (import { cn } from "@/lib/utils") Imported by ./src/app/page.tsx

My Solution:

Create the file frontend/src/lib/utils.ts with contents:

export function cn(...classes: string[]) { return classes.filter(Boolean).join(' '); }

Resolves the issue.

The original error is:

Failed to compile ./src/components/ui/button.tsx:5:0 Module not found: Can't resolve '@/lib/utils' 3 | import { cva, type VariantProps } from "class-variance-authority" 4 |

5 | import { cn } from "@/lib/utils" 6 | 7 | const buttonVariants = cva( 8 | "inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-white transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-gray-950 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 dark:ring-offset-gray-950 dark:focus-visible:ring-gray-300",

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module: ./src/app/page.tsx

MetaNets369 commented 3 months ago

On closer inspection:

The .gitignore file has lib/ listed under the "Distribution / packaging" section, which is causing the frontend/src/lib/utils.ts file to be ignored because lib/ is a parent directory.

To resolve this, you can either:

Remove lib/ from .gitignore:

If you don't need to ignore the lib/ directory for other purposes, you can remove or comment out the lib/ line from your .gitignore file.

Add an Exception for the Specific File:

You can add an exception in the .gitignore file to explicitly include frontend/src/lib/utils.ts.