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
Percy14mo ago
Project ID: 1862ff4f-3f51-4d9c-a0c3-26d926471f99
ojoaoguilherme
ojoaoguilherme14mo 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
Brody14mo ago
are you sure you are calling the api with https?
ojoaoguilherme
ojoaoguilherme14mo 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
Brody14mo ago
what version of node are you using locally and what version is railway using?
ojoaoguilherme
ojoaoguilherme14mo ago
my local version
No description
ojoaoguilherme
ojoaoguilherme14mo ago
how can I see railway node version?
Brody
Brody14mo ago
it would be in the build table at the top of the build logs
ojoaoguilherme
ojoaoguilherme14mo ago
yeap just found it
No description
Brody
Brody14mo ago
set engines.node to 18 in your package.json
ojoaoguilherme
ojoaoguilherme14mo ago
like this?
No description
ojoaoguilherme
ojoaoguilherme14mo ago
No description
Brody
Brody14mo ago
the period denotes an object
ojoaoguilherme
ojoaoguilherme14mo ago
or this ok got it gonna push to see i it works it worked thanksss
Brody
Brody14mo ago
no problem!
Want results from more Discord servers?
Add your server