R
Railway11mo ago
arcoz

dayjs tz function dont work on railway

Hello, is the nodejs Date object handle other that in windows ? I have this error in production Argument gte for where.date.gte is not a valid Date object. but in local i don't have a error
Solution:
I'd write the dockerfile for you, but I'm currently limited to mobile right now
Jump to solution
27 Replies
Percy
Percy11mo ago
Project ID: 152ff848-e90d-48e6-9bfd-f487495da195
arcoz
arcoz11mo ago
how i get the date :
import {DayJS} from '$core/utils/function/dayjs/dayjs';

export const getToday = (): Date => {
return DayJS().tz().set('hour', 0).set('minute', 0).set('seconds', 0).utc().toDate();
};
import {DayJS} from '$core/utils/function/dayjs/dayjs';

export const getToday = (): Date => {
return DayJS().tz().set('hour', 0).set('minute', 0).set('seconds', 0).utc().toDate();
};
Definition of DayJS :
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';

dayjs.extend(utc);
dayjs.extend(timezone);

dayjs.tz.setDefault('Europe/Paris');

export const DayJS = dayjs;
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';

dayjs.extend(utc);
dayjs.extend(timezone);

dayjs.tz.setDefault('Europe/Paris');

export const DayJS = dayjs;
Full error :
PrismaClientValidationError: Argument gte for where.date.gte is not a valid Date object.
at Ui.validate (/app/node_modules/@prisma/client/runtime/library.js:148:73)
at gn.createMessage (/app/node_modules/@prisma/client/runtime/library.js:164:1298)
at /app/node_modules/@prisma/client/runtime/library.js:177:11600
at Object.runInChildSpan (/app/node_modules/@prisma/client/runtime/library.js:174:1394)
at t._executeRequest (/app/node_modules/@prisma/client/runtime/library.js:177:11577)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at getBumpsByUserInGuildToday (/app/src/handlers/database/bump/bump.func.ts:71:24)
at MessageCreate.checkBump (/app/src/events/message_create/message_create.class.ts:106:28) {
clientVersion: '4.16.2'
PrismaClientValidationError: Argument gte for where.date.gte is not a valid Date object.
at Ui.validate (/app/node_modules/@prisma/client/runtime/library.js:148:73)
at gn.createMessage (/app/node_modules/@prisma/client/runtime/library.js:164:1298)
at /app/node_modules/@prisma/client/runtime/library.js:177:11600
at Object.runInChildSpan (/app/node_modules/@prisma/client/runtime/library.js:174:1394)
at t._executeRequest (/app/node_modules/@prisma/client/runtime/library.js:177:11577)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at getBumpsByUserInGuildToday (/app/src/handlers/database/bump/bump.func.ts:71:24)
at MessageCreate.checkBump (/app/src/events/message_create/message_create.class.ts:106:28) {
clientVersion: '4.16.2'
before i don't use .tz() but i got not the good date, it filter with utc timezone, and for my project i neeted French timezone hours
Brody
Brody11mo ago
oh wow I didn't know this was still an issue, and the solution usually ends up being use a Dockerfile
arcoz
arcoz11mo ago
i have found a thing here : https://stackoverflow.com/questions/75129234/day-js-timezone-plugin-method-produce-an-invalid-date a issue with nodejs fixed after 18.13 Is possible to start in a specific minor version or not ?
Stack Overflow
day.js timezone plugin method produce an invalid Date
I used a long time, dayjs in an angular project, to convert timestamps in a rest response from UTC to localtime. After my last update, it does not work anymore. It is not the first problem with day...
Brody
Brody11mo ago
nope, but there's a possibility that specifying node 18 could use a node 18 version greater than 18.13 in your package.json set engines.node to 18
arcoz
arcoz11mo ago
i have add node version in env variable
Brody
Brody11mo ago
and what version is actually being installed
arcoz
arcoz11mo ago
arcoz
arcoz11mo ago
i don't have info about minor version
Mozzy
Mozzy11mo ago
v18.12.1 from one of my bots
Brody
Brody11mo ago
temporarily change your start command to node --version or whatever prints the version lol ah thanks mozzy so I assume if this is fixed in 18.13 it would also be fixed in 19x?
arcoz
arcoz11mo ago
yes i think but nixpacks only accept 14, 16 and 18 no ?
Brody
Brody11mo ago
damn you right well back to the original solution, dockerfile
Gaetan
Gaetan11mo ago
@arcoz no, sorry i don't know
arcoz
arcoz11mo ago
i can use another version of node with that ?
Brody
Brody11mo ago
you can use any version of node even patch versions
Solution
Brody
Brody11mo ago
I'd write the dockerfile for you, but I'm currently limited to mobile right now
arcoz
arcoz11mo ago
okay thanks, docket is a technologie that i have planed to learn but never used right now
Brody
Brody11mo ago
I mean you don't need to know docker to write a dockerfile, I know very little about the docker system myself
arcoz
arcoz11mo ago
FROM node:19

# Create app directory
WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

CMD npm run start:prod
FROM node:19

# Create app directory
WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

CMD npm run start:prod
is this good ? long to build the image localy 🥲
Brody
Brody11mo ago
I recommend npm ci instead of npm install railway can cache most layers of the dockerfile they'd also already have a cache of node:19
arcoz
arcoz11mo ago
okay
arcoz
arcoz11mo ago
https://docs.railway.app/deploy/dockerfiles#environment-variables I need to redeclare all env variable in dockerfile ?
Railway Docs
Dockerfiles | Railway Docs
Documentation for Railway
Brody
Brody11mo ago
not in your case since you aren't using any variables during build time but yeah that's a very basic dockerfile with lots of room for improvement, but it should get you up and running just fine
arcoz
arcoz11mo ago
it work nice ! finaly i use npm install because localy i use pnpm and so don't have a package.lock.json
Brody
Brody11mo ago
I've never seen the point in pnpm, but all good!
arcoz
arcoz11mo ago
okay, thanx for all