Issue with date-fns package

anyone recently having issue with date-fns in railway? my latest deployment is not working due to error Error: Cannot find module '/app/node_modules/date-fns/index.js'. Please verify that the package.json has a valid "main" entry But checking the node_modules manually. the packages files including index.js is found What's weird is that, this only happen today. yesterday the deployment work fine
Solution:
updating the target in your tsconfig.json to es2020 eh?
Jump to solution
114 Replies
Percy
Percy9mo ago
Project ID: d85df9df-e8f2-42e7-81ea-4e1929823be4
Dion Larosa
Dion LarosaOP9mo ago
d85df9df-e8f2-42e7-81ea-4e1929823be4
Brody
Brody9mo ago
please share your repo
Dion Larosa
Dion LarosaOP9mo ago
hmm it's a private repo. but this is the package.json
Dion Larosa
Dion LarosaOP9mo ago
Railway
404 - Page not found
Railway is an infrastructure platform where you can provision infrastructure, develop with that infrastructure locally, and then deploy to the cloud.
Dion Larosa
Dion LarosaOP9mo ago
no changes with the packages today when i rollback to that build its working the strange is that, there is no other update really. and if i try to re deploy using the same code base (no update) the issue will show up is there any issue with the build just today?
Brody
Brody9mo ago
this is unlikely to be a specific railway issue
Error: Cannot find module '/app/node_modules/date-fns/index.js'. Please verify that the package.json has a valid "main" entry
Error: Cannot find module '/app/node_modules/date-fns/index.js'. Please verify that the package.json has a valid "main" entry
Please verify that the package.json has a valid "main" entry
Please verify that the package.json has a valid "main" entry
have you done this? another reason this could be happening, are you commiting your node_modules folder to github?
Dion Larosa
Dion LarosaOP9mo ago
No, im not comitting node_modules to github yeah, I thought of that as well that its not a railway issue. but what bugs me is that it just happen with todays deployments btw, this is a nestjs project
Brody
Brody9mo ago
Please verify that the package.json has a valid "main" entry
Please verify that the package.json has a valid "main" entry
Dion Larosa
Dion LarosaOP9mo ago
oh yeah there's none. I will try to add same think that error points to date-fns package
Brody
Brody9mo ago
please provide a build log from the working build. and then a build log from the most recent broken build. https://bookmarklets.up.railway.app/log-downloader/
Dion Larosa
Dion LarosaOP9mo ago
Brody
Brody9mo ago
that is the deploy logs, please provide build logs
Dion Larosa
Dion LarosaOP9mo ago
ohh im seeing "No build logs found for deployment" with working build. few min I will revert to this build and see if build logs will be populated
Brody
Brody9mo ago
sounds good in the mean time, please send the build logs for the newest broken build
Dion Larosa
Dion LarosaOP9mo ago
done reverting the working build. I see "No build logs found for deployment" still. maybe this is because it has been build before and was pulled from cache now?
No description
Dion Larosa
Dion LarosaOP9mo ago
ok let me pull up the latest build logs with current with error
Dion Larosa
Dion LarosaOP9mo ago
one with error build
Brody
Brody9mo ago
can you revert your repo to the point in time the last successful deployment was made?
Dion Larosa
Dion LarosaOP9mo ago
I did that earlier and able to experienced the issue. but I will try again now for you
Brody
Brody9mo ago
do you have the date from when you made the last successful deployment? (not a revert)
Dion Larosa
Dion LarosaOP9mo ago
it was on Feb 28, 2024 10:10 pm btw, I just revert my repo to last working build and it fails
Dion Larosa
Dion LarosaOP9mo ago
No description
Brody
Brody9mo ago
you reverted the repo to before feb 28th?
Dion Larosa
Dion LarosaOP9mo ago
on i've reverted on that date(feb 28). that's the first time I deploy this project in railway btw, a note as well. I have other project using date-fns deployed in railway - been running almost a year already now with this error. im afraid if we deploy to the other project might have the same issue 😄
Brody
Brody9mo ago
can you try deleting your yarn lock file and then re-syncing it you can bring your repo back up to date now
Dion Larosa
Dion LarosaOP9mo ago
yeah actually done that as well earlier as well. I will do it again for you
Brody
Brody9mo ago
would you happen to know the node version in use by the last working build?
Dion Larosa
Dion LarosaOP9mo ago
hmm no but earlier while debuggin. I logged in server from my local using cli. I checked the node version in server and setup the same version in my local. Im not able to experience the same error in my local
Brody
Brody9mo ago
the cli does not allow you to "log in" to the container you where running commands locally
Dion Larosa
Dion LarosaOP9mo ago
ohh I was running railway run node -v thought that's from server
Brody
Brody9mo ago
that runs the command locally
Dion Larosa
Dion LarosaOP9mo ago
ok, thanks for correcting
Brody
Brody9mo ago
does the package.json have a valid main entry now?
Dion Larosa
Dion LarosaOP9mo ago
ahh updating back. was reverted earlier updated. same error
Brody
Brody9mo ago
would you be willing to add me to the repo?
Dion Larosa
Dion LarosaOP9mo ago
sure yeah pls share your github email I will give you read access
Brody
Brody9mo ago
brody192
Dion Larosa
Dion LarosaOP9mo ago
ok let me add you added you already https://github.com/ASP-PH/fuel-api
Brody
Brody9mo ago
what branch is railway set to deploy from?
Dion Larosa
Dion LarosaOP9mo ago
develop
Brody
Brody9mo ago
is dist/main.js the correct path to the generated file?
Dion Larosa
Dion LarosaOP9mo ago
ohh wait let me double check ohhh should be dist/src/main.js 🤦‍♂️ will try to deploy
Brody
Brody9mo ago
is this the path the main.js file ends up being put locally?
Dion Larosa
Dion LarosaOP9mo ago
yeah for yarn build command done, same error
Brody
Brody9mo ago
wait why is date-fns being used?
Dion Larosa
Dion LarosaOP9mo ago
for my date helpers. thats found in src/utils/date.ts
Brody
Brody9mo ago
have you told me your local node version?
Dion Larosa
Dion LarosaOP9mo ago
im currently using 18.18.1
Brody
Brody9mo ago
as far as i know, railway would be using node 18.19
Dion Larosa
Dion LarosaOP9mo ago
ohh ok. I can update I can't see any obvious reasons why this error is showing and only in railway
Brody
Brody9mo ago
just some tiny config issue, its a tricky one
Dion Larosa
Dion LarosaOP9mo ago
hmm yeah
Brody
Brody9mo ago
your start script is nest start are you sure this is running the built main.ts file? maybe try changing your start command on railway to your start:prod script?
Dion Larosa
Dion LarosaOP9mo ago
did that already and the build I set to yarn build ohh2 it seems working already with my latest push
Solution
Brody
Brody9mo ago
updating the target in your tsconfig.json to es2020 eh?
Dion Larosa
Dion LarosaOP9mo ago
yeah seems that fixed it
Brody
Brody9mo ago
awsome, see, just a tiny misconfiguration
Dion Larosa
Dion LarosaOP9mo ago
haha thank you so much for the help!
Brody
Brody9mo ago
no problem, happy you where able to solve this feel free to remove me from th github repo 🙂
Dion Larosa
Dion LarosaOP9mo ago
Buy Me a Coffee
Brody is Helping in the Railway Community Discord server!
Hello! 👋I don't work for Railway 🫠
Dion Larosa
Dion LarosaOP9mo ago
will remove you in the repo
Brody
Brody9mo ago
i was trying to figure out who that was lol thank you for the train!
Dion Larosa
Dion LarosaOP9mo ago
lol sure, welcome
Dion Larosa
Dion LarosaOP9mo ago
Hi @Brody im seeing the issue again. nothing is changed in my end I mean no updates for compiler hahaha question, does railway randomly change their builder?
Dion Larosa
Dion LarosaOP9mo ago
Actually this already happen yesterday. I didn't notice the failed build. This is the build log yerterday. it shows network error.
Dion Larosa
Dion LarosaOP9mo ago
it's givin me headache already hahaha can't focus on my development lol
Brody
Brody9mo ago
first build log is for an issue with date-fns, second build log is an issue with cache, what is the current issue you get?
Dion Larosa
Dion LarosaOP9mo ago
the issue with date-fns is the latest hmm I will try to clear cache by running railway run yarn cache clean
Brody
Brody9mo ago
that does not clear the cache on railway
Dion Larosa
Dion LarosaOP9mo ago
ohh ok
Brody
Brody9mo ago
that runs a local command
Dion Larosa
Dion LarosaOP9mo ago
ok
Brody
Brody9mo ago
so the latest build is failing because it can't find date-fns?
Dion Larosa
Dion LarosaOP9mo ago
yeah same as before the one fixed already with changing tsconfig > target > 2022 is there a way to know what node version or how railway build? what i know only is that its using nixpacks
Brody
Brody9mo ago
node 18, printed at the top of the build logs have you modified your package.json? this is a different error from before, this time it just looks like it's outright not being installed
Dion Larosa
Dion LarosaOP9mo ago
no nothing
Brody
Brody9mo ago
add me back to the repo?
Dion Larosa
Dion LarosaOP9mo ago
sure2 added
Brody
Brody9mo ago
what branch is currently set to deploy to railway?
Dion Larosa
Dion LarosaOP9mo ago
develop
Dion Larosa
Dion LarosaOP9mo ago
these are test commits I did to try to fix the issue after the error build
No description
Brody
Brody9mo ago
I've probably asked you this before, but you do use yarn locally right?
Dion Larosa
Dion LarosaOP9mo ago
yeah i use yarn in my local
Brody
Brody9mo ago
what version?
Dion Larosa
Dion LarosaOP9mo ago
v1.22.21
Brody
Brody9mo ago
okay close enough to what railway uses can you delete the lock file, and then regenerate it, let me know if git says it has changed
Dion Larosa
Dion LarosaOP9mo ago
ok. I did that already earlier tho nothing change
Dion Larosa
Dion LarosaOP9mo ago
No description
Brody
Brody9mo ago
so how opposed would you be to switching to just npm as a test? (I'm running out of ideas) aka delete your yarn lock file and generate an npm lock file with npm install
Dion Larosa
Dion LarosaOP9mo ago
hmm been a while since i use npm 😄 tho I will try if that solve the issue
Brody
Brody9mo ago
and to answer this question, yes they do, not intentionally, they rebase the image to get some os level security updates and sometimes they change the version of nix being used and that also can cause issues. but railway has not changed the builder since we last talked.
Dion Larosa
Dion LarosaOP9mo ago
ok cool. noted btw, deploying with npm
Brody
Brody9mo ago
is the install command listed as npm ci?
Dion Larosa
Dion LarosaOP9mo ago
hmm think might be cache. after this I will back to yarn and try this NO_CACHE option https://docs.railway.app/guides/build-configuration
Railway Docs
Build Configuration | Railway Docs
Documentation for Railway
Dion Larosa
Dion LarosaOP9mo ago
sorry didn't get you ohh npm works build is green
Brody
Brody9mo ago
in the build table at the top of the build logs
Dion Larosa
Dion LarosaOP9mo ago
i'll try yarn now if it fail again
Dion Larosa
Dion LarosaOP9mo ago
ahh yeah it is
No description
Brody
Brody9mo ago
yeah this might be a cache issue
Dion Larosa
Dion LarosaOP9mo ago
deploying now with yarn using no cache option
Dion Larosa
Dion LarosaOP9mo ago
nah it worked 😄
No description
Dion Larosa
Dion LarosaOP9mo ago
I guess caching needs to be fixed by railway. for now, I will add no cache whenever I experienced this issue this is not good tho. we choose railway so can just focus directly on development with 0 configs on server Thank you! it's good chatting with someone with your knowledge. I get ideas hehe
Brody
Brody9mo ago
while this particular experience is not good, from personal experience, unfortunately there is no such thing as zero configuration deployments, on any platform
Dion Larosa
Dion LarosaOP9mo ago
yeah agree but something like this error is kind of frustrating 😄
Brody
Brody9mo ago
I agree
Dion Larosa
Dion LarosaOP9mo ago
or railway might add this as a note in the docs
Brody
Brody9mo ago
that's fair
Dion Larosa
Dion LarosaOP9mo ago
i'll remove you from repo now. Have a great day ahead. Thank you for your help!
Brody
Brody9mo ago
happy to help!
Dion Larosa
Dion LarosaOP9mo ago
ohh just fyi. i removed no cache and it fails again. seems I can't use cache for now hehe if you have any updte on the caching pls let me know
Brody
Brody9mo ago
the cache on the host machine is likely in a bad state, best to keep the no cache variable
Want results from more Discord servers?
Add your server