ReferenceError: FormData is not defined in Production

Hello, my codes are working fine on localhost, but when I push the codes to railway it throws this message when hitting the endpoint
15 Replies
Percy
Percy11mo ago
Project ID: 1862ff4f-3f51-4d9c-a0c3-26d926471f99
ojoaoguilherme
ojoaoguilherme11mo ago
1862ff4f-3f51-4d9c-a0c3-26d926471f99 this is the peace of code that is working on localhost and throwing on railway
@Post(":id")
@UseGuards(JwtAuthGuard)
@UseInterceptors(FilesInterceptor("files"))
async updateLand(
@Param("id") land: string,
@Res() res: Response,
@Body() body: LandUpdateType,
//@UploadedFiles() files: Express.Multer.File[],
//@Req() req: Request,
) {

const { name, description, tokenId, buildingModelId } = body;
console.log(
"Receiving data",
name,
description,
tokenId,
buildingModelId,
); // this is loging on localhost and railway logs

const formData = new FormData();
formData.append("Name", name);
formData.append("Description", description);
formData.append("TokenID", tokenId);
formData.append("BuildingModelID", buildingModelId);

const { data, status } = await axios.post(
<My other endpoint>,
formData,
);
if (status === HttpStatus.OK) {
res.status(status).end();
} else {
res.status(status).json(data);
}
} catch (error) {
console.log(error);
res.status(HttpStatus.BAD_REQUEST).send(error);
}
}
@Post(":id")
@UseGuards(JwtAuthGuard)
@UseInterceptors(FilesInterceptor("files"))
async updateLand(
@Param("id") land: string,
@Res() res: Response,
@Body() body: LandUpdateType,
//@UploadedFiles() files: Express.Multer.File[],
//@Req() req: Request,
) {

const { name, description, tokenId, buildingModelId } = body;
console.log(
"Receiving data",
name,
description,
tokenId,
buildingModelId,
); // this is loging on localhost and railway logs

const formData = new FormData();
formData.append("Name", name);
formData.append("Description", description);
formData.append("TokenID", tokenId);
formData.append("BuildingModelID", buildingModelId);

const { data, status } = await axios.post(
<My other endpoint>,
formData,
);
if (status === HttpStatus.OK) {
res.status(status).end();
} else {
res.status(status).json(data);
}
} catch (error) {
console.log(error);
res.status(HttpStatus.BAD_REQUEST).send(error);
}
}
Brody
Brody11mo ago
are you sure you are calling the api with https?
ojoaoguilherme
ojoaoguilherme11mo ago
yes on the <my other endpoint> its https://<domain>/<endpoint> I am also receiving the data in the controller here as formdata from my nextjs application, maybe it helps you out...
Brody
Brody11mo ago
what version of node are you using locally and what version is railway using?
ojoaoguilherme
ojoaoguilherme11mo ago
my local version
No description
ojoaoguilherme
ojoaoguilherme11mo ago
how can I see railway node version?
Brody
Brody11mo ago
it would be in the build table at the top of the build logs
ojoaoguilherme
ojoaoguilherme11mo ago
yeap just found it
No description
Brody
Brody11mo ago
set engines.node to 18 in your package.json
ojoaoguilherme
ojoaoguilherme11mo ago
like this?
No description
ojoaoguilherme
ojoaoguilherme11mo ago
No description
Brody
Brody11mo ago
the period denotes an object
ojoaoguilherme
ojoaoguilherme11mo ago
or this ok got it gonna push to see i it works it worked thanksss
Brody
Brody11mo ago
no problem!