Railway-specific error
It works fine when running locally:
Error: ENOENT: no such file or directory, open '/app/build/messages.json'
Solution:Jump to solution
alright, I fixed it by hosting messages.json in a github gist rather than in the project files
13 Replies
Project ID:
a3d167c9-773f-4271-a6bc-99089387a3b6
a3d167c9-773f-4271-a6bc-99089387a3b6
i think it's probably because of this part of the code:
i used dirname for message.json:
```js
const jsonData = JSON.parse(readFileSync(join(dirname, 'messages.json'), 'utf8'));
```
like that
maybe that doesn't work with railway?
maybe __dirname isn't good in railway?
what's the alternative then?
is the
messages.json
in your root folder?
mind showing me your filetree?in my local project folder
When you compile your typescript to javascript, it'll take every
.ts
file in your src
folder and create the .js
version in build
since your messages.json
is not a .ts
file, it's ignored by the builder and is not sent to build
This means when you run your project in typescript then it'll work because the messages.json
file is present, but when you run in production with javascript, then it won't work because messages.json
is not present in your build
folder
To fix this, you'd want to move your messages.json
file to the root directory
and then access it with:
that way you can access it both from your typescript dev folder and your production folderno, the json file does appear in build.
it works when run locally, but not when it's on railway
oh you're right, my fault
i think it's probably because __dirname doesn't work on railway for some reason
maybe file system is different or something
I've never had issues with
__dirname
š¤__dirname looks like this
since apparently __dirname is only for commonjs modules or something
maybe railway's file system is weird idk
ah, i've got it
it's because you can't use file system functions in something like railway apparently
since it's a web-based environment or something
You definitally can use file system functions
Solution
alright, I fixed it by hosting messages.json in a github gist rather than in the project files