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

a year 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

24 Replies

sgalvao
HOBBYOP

a year ago

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


a year 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?


sgalvao
HOBBYOP

a year ago

i will do it now, just a sec


sgalvao
HOBBYOP

a year ago

its working fine locally

1338520213108293600


a year ago

after cleaning your modules and re-installing?


sgalvao
HOBBYOP

a year ago

yep


sgalvao
HOBBYOP

a year ago

on railway

1338520696862802000


a year ago

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

Will let someone else take a stab.


a year ago

stupid one: did you import/define it it?


sgalvao
HOBBYOP

a year ago

i checked, it is on last version


sgalvao
HOBBYOP

a year ago

haha, yep


sgalvao
HOBBYOP

a year ago

actually that import its inside the nestJS module


a year ago

Are you using nixpacks or your own dockerfile?


sgalvao
HOBBYOP

a year ago

nixpacks


a year ago

If so, nixpacks defaults to Node 18 according to docs



a year ago

and this is in a server component?


a year ago

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


sgalvao
HOBBYOP

a year ago

okay


a year ago

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


sgalvao
HOBBYOP

a year ago

thaanks broo, it worked


sgalvao
HOBBYOP

a year ago

❤️


a year ago

thank you medim!


a year ago

!s


Status changed to Solved brody about 1 year ago


Loading...