Running npx prisma db seed after deployment

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:

Running seed command node --require esbuild-register prisma/seed.ts
throw err;

Error: Cannot find module ‘esbuild-register’
Require stack:

  • 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:

  1. 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.

  2. Run the seed command in your Dockerfile and check everything is working locally then deploy using your updated Dockerfile.

  3. 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.

ok, will try those options - thanks for the response

1 Like