Issue with crypto.randomUUID() in NestJS/Schedule on Railway

sgalvaoHOBBY

4 months ago

I'm running a NestJS project on Railway and using @nestjs/schedule for task scheduling. Everything works fine locally, but when deployed to Railway, I get the following error:

ReferenceError: crypto is not defined at SchedulerOrchestrator.addCron (/app/node_modules/@nestjs/schedule/dist/scheduler.orchestrator.js:90:38)
It seems that Railway's environment is not properly loading the native crypto module, which is available in Node.js 20+.

Has anyone encountered this issue before or knows how to force the crypto module to load properly on Railway?

Solved

0 Replies

sgalvaoHOBBY

4 months ago

6ab1fc58-0f6e-4c6a-8158-6a3b9c8fb0f4


4 months ago

Can you clean your node modules locally to see if you have something cached that's misleading you into thinking your build is working?


sgalvaoHOBBY

4 months ago

i will do it now, just a sec


sgalvaoHOBBY

4 months ago

its working fine locally

1338520213108293600


4 months ago

after cleaning your modules and re-installing?


sgalvaoHOBBY

4 months ago

yep


sgalvaoHOBBY

4 months ago

on railway

1338520696862802000


4 months ago

Not personally sure, my node knowledge is weak - so, check nestjs/schedule is up to date.

Will let someone else take a stab.


4 months ago

stupid one: did you import/define it it?


sgalvaoHOBBY

4 months ago

i checked, it is on last version


sgalvaoHOBBY

4 months ago

haha, yep


sgalvaoHOBBY

4 months ago

actually that import its inside the nestJS module


4 months ago

Are you using nixpacks or your own dockerfile?


sgalvaoHOBBY

4 months ago

nixpacks


4 months ago

If so, nixpacks defaults to Node 18 according to docs



4 months ago

and this is in a server component?


4 months ago

override it with some of the options shown here and try building again


sgalvaoHOBBY

4 months ago

okay


4 months ago

the crypto package was only globally available in node in version >=19 afaik


sgalvaoHOBBY

4 months ago

thaanks broo, it worked


sgalvaoHOBBY

4 months ago

❤️


4 months ago

thank you medim!


4 months ago

!s


Status changed to Solved brody 4 months ago


Issue with crypto.randomUUID() in NestJS/Schedule on Railway - Railway Help Station