I’m able to deploy a remix app, however its not running my seed.ts file (per the Remix | Jokes App) instructions.
I’d like to run the seed.ts on the deployed instance after the deploy has finished. I’m able to ssh to the app and run npx commands, but when i run “npx prisma db seed” I get the error:
internal/preload
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at Module._preloadModules (node:internal/modules/cjs/loader:1282:12)
at loadPreloadModules (node:internal/bootstrap/pre_execution:539:5)
at prepareMainThreadExecution (node:internal/bootstrap/pre_execution:85:3)
at node:internal/main/run_main_module:7:1 {
code: ‘MODULE_NOT_FOUND’,
requireStack: [ ‘internal/preload’ ]
I’ve tried installing esbuild but that doesn’t seem to work. Does anyone have any info on how to get this to work? Thanks
That npx command probably relies on dev dependencies that aren’t present when deployed. A few ideas:
Maybe try running npm install on the instance and try again. You could also install esbuild-register but who knows what other dependencies will be missing afterwards.
Run the seed command in your Dockerfile and check everything is working locally then deploy using your updated Dockerfile.
Deploy a fly db, proxy it, and run this seed command against your local deps. Then deploy the app connected to the pre-seeded DB.
Option 2 is great for getting things up and running reliably, but 3 makes sense if you need to scale this app to more instances and you don’t want to include data seeding in the image.
Hi all, for reference, I got it working after some trial and error. @jmsfbs answer guided me a bit.
So what I do is have the prisma in package.json be
"prisma": {
"seed": "ts-node prisma/seed.ts"
}
This seed file uses data files via require and the data files must be included in the build (you could put it in public or in /prisma for example). There is no seeding when I deploy with flyctl deploy. When deployed however, then I do flyctl ssh console to ssh into the current app, then cd myapp then i run npx ts-node prisma/seed.ts which asks me if I want to install ts-node, y → seeding is starting.
I know this is not ideal, but I was getting frustrated by my total inexperience with docker and build processes, so it ended up being just fine sshing into production and running scripts there.
I couldn’t get any of the above solutions to work… Instead, what I did was compiled the seed to .js, and then in my fly.toml file, I set my release command to be: release_command = "bash -c 'npx prisma migrate deploy && npx node prisma/seed.js'". This seemed to work!
Thanks for this, yeah frustratingly none of these worked for me either so I did the same as you. It definitely feels like this should be easier somehow. Running npm install (somedep) through fly console didn’t seem to do anything for some reason.
Hey, thanks for the reply. I had a look at the post you linked but unfortunately couldn’t see anything that solves my initial issue. Still, as I say, @wengzilla’s post helped me out, I’m just a bit surprised running npm install doesn’t do anything: