Open MuskanNazim opened 2 weeks ago
The plan to solve the bug involves two main steps: updating the Next.js version and correcting the import statement for the authentication library in the IncomeList.jsx
file. The reasoning behind this solution is based on the error message and the analysis of the relevant files.
package.json
file, appears to be @clerk/nextjs
. Updating the import statement in IncomeList.jsx
to use @clerk/nextjs
should resolve the issue.The bug is caused by two main issues:
IncomeList.jsx
is incorrect. The file attempts to import useUser
from 'some-auth-library', which does not exist. The correct library, as indicated in the package.json
file, is @clerk/nextjs
.package.json
First, update the Next.js version in package.json
to the latest version:
{
"dependencies": {
"next": "^14.2.3", // or the latest version available
"@clerk/nextjs": "^4.0.0" // Ensure this is the correct version
}
}
IncomeList.jsx
Next, update the import statement in IncomeList.jsx
to use the correct authentication library:
"use client";
import React, { useEffect, useState } from "react";
import CreateIncomes from "./CreateIncomes";
import { db } from "@/utils/dbConfig";
import { desc, eq, getTableColumns, sql } from "drizzle-orm";
import { Incomes, Expenses } from "@/utils/schema";
import { useUser } from "@clerk/nextjs"; // Corrected import statement
import IncomeItem from "./IncomeItem";
function IncomeList() {
const [incomelist, setIncomelist] = useState([]);
const { user } = useUser();
useEffect(() => {
user && getIncomelist();
}, [user]);
const getIncomelist = async () => {
const result = await db
.select({
...getTableColumns(Incomes),
totalSpend: sql`sum(${Expenses.amount})`.mapWith(Number),
totalItem: sql`count(${Expenses.id})`.mapWith(Number),
})
.from(Incomes)
.leftJoin(Expenses, eq(Incomes.id, Expenses.budgetId))
.where(eq(Incomes.createdBy, user?.primaryEmailAddress?.emailAddress))
.groupBy(Incomes.id)
.orderBy(desc(Incomes.id));
setIncomelist(result);
};
return (
<div className="mt-7">
<div
className="grid grid-cols-1
md:grid-cols-2 lg:grid-cols-3 gap-5"
>
<CreateIncomes refreshData={() => getIncomelist()} />
{incomelist?.length > 0
? incomelist.map((budget, index) => (
<IncomeItem budget={budget} key={index} />
))
: [1, 2, 3, 4, 5].map((item, index) => (
<div
key={index}
className="w-full bg-slate-200 rounded-lg
h-[150px] animate-pulse"
></div>
))}
</div>
</div>
);
}
export default IncomeList;
To replicate the bug, follow these steps:
IncomeList.jsx
file contains the incorrect import statement:
import { useUser } from 'some-auth-library';
By following these steps, you should encounter the same build error described in the ticket.
Click here to create a Pull Request with the proposed solution
Files used for this task:
Build Error Failed to compile
Next.js (14.2.2) out of date (learn more) ./app/(routes)/dashboard/incomes/_components/IncomeList.jsx:3:1 Module not found: Can't resolve 'some-auth-library' 1 | "use client" 2 | import React, { useState, useEffect } from 'react';
https://nextjs.org/docs/messages/module-not-found