Cannot Import Function from another file
Answered
shadow posted this in #help-forum
shadowOP
Hey devs, currently im trying import an function that is implemented at:
and the file where im trying to use the function is at:
this is the function im trying to import:
but when i try to call that function on
.
└── utils/
└── Auctions.tsxand the file where im trying to use the function is at:
.
└── app/
└── api/
└── auction/
└── [auctionID]/
└── route.jsthis is the function im trying to import:
export async function fetchDetails(auctionID: string) {
const response = await fetch(
`https://api.example.com/api/auctions/${auctionID}`
);
const data = await response.json();
return data;
}but when i try to call that function on
route.js i get nothing.route.jsimport { NextResponse } from "next/server";
import { fetchDetails } from "@utils/Auctions";
export async function GET(req, { params }) {
const auctionID = params.auctionID;
if (!auctionID) {
return NextResponse.json({ error: "No Auction ID provided." }, { status: 400 });
}
const data = await fetchDetails(auctionID);
return NextResponse.json(data, { status: 200 });
}tsconfig.json{
"compilerOptions": {
/...
"paths": {
"@/*": ["./*"],
"@utils/*": ["./utils/*"],
}
},
/...
}Answered by European sprat
but you don't actually need @utils since @/* will allow you to use @/utils/
6 Replies
European sprat
Maybe you need to define utils before @/* ? in tsconfig
European sprat
but you don't actually need @utils since @/* will allow you to use @/utils/
Answer
@European sprat but you don't actually need @utils since @/* will allow you to use @/utils/
shadowOP
so i should import the function like this?
import { fetchDetails } from "@/utils/Auctions";tsconfig.json{
"compilerOptions": {
/...
"paths": {
"@/*": ["./*"],
}
},
/...
}European sprat
does it work?
@European sprat does it work?
shadowOP
i think the problem is from the api itself, im getting
SyntaxError: Unexpected end of JSON inputoh my god i had an syntax error in the endpoint lmao