2 months ago
I am using the official Railway template for Ghost from https://railway.com/new/template/ghost
Upon initialization, the MySQL works but the Ghost app fails at the step yarn install --frozen-lockfile.
Full output below:
yarn install v1.22.22
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
warning casper@4.7.5: The engine "ghost" appears to be invalid.
warning ghost@4.47.4: The engine "cli" appears to be invalid.
warning lyra@1.0.0: The engine "ghost" appears to be invalid.
warning lyra@1.0.0: The engine "ghost-api" appears to be invalid.
[4/5] Linking dependencies...
warning "ghost > bookshelf@1.2.0" has incorrect peer dependency "knex@>=0.15.0 <0.22.0".
[5/5] Building fresh packages...
$ bin/alter-auth-method && bash bin/cloudinary.sh && bash bin/themes.sh
/app/node_modules/mysql2/lib/connection_config.js:77
this.isServer = options.isServer;
^
TypeError: Cannot read properties of undefined (reading 'isServer')
at new ConnectionConfig (/app/node_modules/mysql2/lib/connection_config.js:77:29)
at Object.exports.createConnection (/app/node_modules/mysql2/index.js:10:35)
at alterAuthenticationMethod (/app/bin/alter-auth-method:17:26)
at Object.<anonymous> (/app/bin/alter-auth-method:14:1)
at Module._compile (node:internal/modules/cjs/loader:1198:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
at Module.load (node:internal/modules/cjs/loader:1076:32)
at Function.Module._load (node:internal/modules/cjs/loader:911:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:22:47
error Command failed with exit code 1.
Pinned Solution
2 months ago
Hello bhavesh;
the crash happens in bin/alter-auth-method which runs during yarn install (build time). you can confirm this yourself by checking package.json in the template repo , postinstall calls it before the app even starts.
the problem is that script tries to connect to mysql using mysql2, but the mysql environment variables are not available yet at build time on railway, so it gets undefined and crashes.
the fix is to fork the template repo, move bin/alter-auth-method out of postinstall and into the start script so it runs at runtime instead, when the mysql vars are actually available. then deploy your fork instead of the official template.
you can verify this by checking the contents of bin/alter-auth-method in the repo yourself to see exactly which env vars it reads
Hope this help you :)
2 Replies
Status changed to Awaiting Railway Response Railway • about 2 months ago
Status changed to Open Railway • about 2 months ago
2 months ago
Hello bhavesh;
the crash happens in bin/alter-auth-method which runs during yarn install (build time). you can confirm this yourself by checking package.json in the template repo , postinstall calls it before the app even starts.
the problem is that script tries to connect to mysql using mysql2, but the mysql environment variables are not available yet at build time on railway, so it gets undefined and crashes.
the fix is to fork the template repo, move bin/alter-auth-method out of postinstall and into the start script so it runs at runtime instead, when the mysql vars are actually available. then deploy your fork instead of the official template.
you can verify this by checking the contents of bin/alter-auth-method in the repo yourself to see exactly which env vars it reads
Hope this help you :)
domehane
Hello **bhavesh;** the crash happens in bin/alter-auth-method which runs during yarn install (build time). you can confirm this yourself by checking package.json in the template repo , postinstall calls it before the app even starts. the problem is that script tries to connect to mysql using mysql2, but the mysql environment variables are not available yet at build time on railway, so it gets undefined and crashes. the fix is to fork the template repo, move bin/alter-auth-method out of postinstall and into the start script so it runs at runtime instead, when the mysql vars are actually available. then deploy your fork instead of the official template. you can verify this by checking the contents of bin/alter-auth-method in the repo yourself to see exactly which env vars it reads Hope this help you :)
2 months ago
awesome, thanks for the reply! I didn't try this solution because I found a community-contributed Ghost template which just worked out of the box (I think it's the one by alphasec). So I am going to close the current issue, and mark your answer as the solution for any future person who wants to stick to the Railway-provided template and apply your mod.
Status changed to Solved brody • about 2 months ago