3 months ago
npm warn config production Use --omit=dev instead.
sh: 1: prisma: not found
25 Replies
3 months ago
Prisma is probably in your devDependencies but Railway skips those by default. Either move it to regular dependencies with npm install prisma --save, or add NPM_CONFIG_PRODUCTION=false to your Railway env variables so dev dependencies get installed during build.
3 months ago
Or you can install your npm packages with the development dependencies.
dardameiz
Prisma is probably in your devDependencies but Railway skips those by default. Either move it to regular dependencies with npm install prisma --save, or add NPM_CONFIG_PRODUCTION=false to your Railway env variables so dev dependencies get installed during build.
3 months ago
Let me try this
samuelamofa
Let me try this
3 months ago
it didn't work
3 months ago
whats the error?
dardameiz
whats the error?
3 months ago
Starting Container
npm warn config production Use --omit=dev instead.
sh: 1: prisma: not found
npm warn config production Use --omit=dev instead.
sh: 1: prisma: not found
npm warn config production Use --omit=dev instead.
sh: 1: prisma: not found
npm warn config production Use --omit=dev instead.
sh: 1: prisma: not found
npm warn config production Use --omit=dev instead.
sh: 1: prisma: not found
npm warn config production Use --omit=dev instead.
sh: 1: prisma: not found
npm warn config production Use --omit=dev instead.
sh: 1: prisma: not found
npm warn config production Use --omit=dev instead.
sh: 1: prisma: not found
npm warn config production Use --omit=dev instead.
sh: 1: prisma: not found
npm warn config production Use --omit=dev instead.
sh: 1: prisma: not found
npm warn config production Use --omit=dev instead.
sh: 1: prisma: not found
3 months ago
That error is happening at container start, not build so the start command is probably trying to run prisma. Check the start script in package.json, if it has something like prisma generate && node server.js, change it to just node server.js and move the prisma generate to your build command instead. Prisma generate only needs to run once during build, not every time the container starts.
dardameiz
That error is happening at container start, not build so the start command is probably trying to run prisma. Check the start script in package.json, if it has something like prisma generate && node server.js, change it to just node server.js and move the prisma generate to your build command instead. Prisma generate only needs to run once during build, not every time the container starts.
3 months ago
scripts": {
"dev": "nodemon server.js",
"start": "node scripts/migrate-and-start.js",
"start:server": "node server.js",
"build": "node scripts/generate-prisma.js",
"migrate": "npx prisma migrate dev",
"migrate:deploy": "npx prisma migrate deploy",
"migrate:runtime": "node scripts/migrate-runtime.js",
"migrate:baseline": "node scripts/baseline-postgresql.js",
"generate": "node scripts/generate-prisma.js",
"seed": "node prisma/seed-production.js",
"seed:production": "node prisma/seed-production.js",
"seed:dev": "node prisma/seed-dev.js",
"seed:meals": "node prisma/seed-ghanaian-meals.js"
3 months ago
The migrate-and-start.js script is probably running prisma commands internally. Either change your start command to just node server.js and run migrations separately, or share what’s inside scripts/migrate-and-start.js so we can see what it’s doing. Migrations shouldn’t run on every container start anyway in my opinion, do them once during deploy or manually.
3 months ago
I'm sharing what's inside scripts/migrate-and-start.js
3 months ago
rakesh it did not work for him , waiting for the migrate and start js.
dardameiz
The migrate-and-start.js script is probably running prisma commands internally. Either change your start command to just node server.js and run migrations separately, or share what’s inside scripts/migrate-and-start.js so we can see what it’s doing. Migrations shouldn’t run on every container start anyway in my opinion, do them once during deploy or manually.
3 months ago
I'm not able to past the script here
3 months ago
"scripts": {
"dev": "nodemon server.js",
"build": "npx prisma generate",
"start": "node server.js",
"migrate:deploy": "npx prisma migrate deploy",
"seed:production": "node prisma/seed-production.js"
3 months ago
require('dotenv').config();
const { spawn } = require('child_process');
const path = require('path');
// Change to backend directory to ensure relative paths work correctly
process.chdir(path.join(__dirname, '..'));
console.log('🚀 Starting backend service...');
console.log('');
// Validate DATABASE_URL is set
if (!process.env.DATABASE_URL) {
console.error('❌ ERROR: DATABASE_URL environment variable is required!');
console.error('');
console.error('Please set DATABASE_URL in your deployment environment:');
console.error(' - Railway: Go to Service → Variables → Add DATABASE_URL');
console.error(' - Format: postgresql://user:password@host:port/database?schema=public');
console.error('');
process.exit(1);
}
/**
* Runs `prisma migrate deploy` to apply pending migrations
*
* Important: `prisma migrate deploy` exits with code 0 if:
* - Migrations are successfully applied
* - All migrations are already applied (up to date)
*
* It only exits with non-zero code if there's an actual error.
* Even in error cases, we start the server to prevent Railway restart loops.
* The server will fail at runtime if there are critical database issues.
*
* Returns: { success: boolean, exitCode: number }
*/
function runMigrations() {
return new Promise((resolve) => {
console.log('📋 Running database migrations...');
console.log(' Command: npx prisma migrate deploy');
console.log('');
const migrateProcess = spawn('npx', ['prisma', 'migrate', 'deploy'], {
stdio: 'inherit', // Pipe output directly to console for Railway logs
env: process.env,
shell: true,
});
// Handle process execution errors (e.g., command not found)
migrateProcess.on('error', (error) => {
console.error('');
console.error('❌ Failed to execute migration command:', error.message || String(error));
console.error(' This may indicate Prisma CLI is not installed');
console.error(' Server will start anyway to prevent restart loop');
console.error(' Check that "prisma" is in dependencies (not devDependencies)');
console.log('');
resolve({
success: false,
exitCode: 1,
});
});
migrateProcess.on('close', (code) => {
if (code === 0) {
// Success: migrations applied or already up to date
console.log('');
console.log('✅ Database migrations completed successfully');
console.log(' (Migrations were applied or already up to date)');
console.log('');
resolve({ success: true, exitCode: 0 });
} else {
// Migration failed with non-zero exit code
// Note: We log a warning but still resolve (not reject) to continue execution
// This prevents Railway restart loops. The server will handle runtime errors.
console.log('');
console.warn('⚠️ Migration deployment exited with code:', code);
console.warn(' This indicates a migration error occurred');
console.warn(' Server will start anyway to prevent restart loops');
console.warn(' Check logs above for migration error details');
console.warn(' If database is not ready, server will fail at runtime');
console.log('');
resolve({
success: false,
exitCode: code,
});
}
});
});
}
/**
* Starts the Express server
* This function never returns - it runs the server process
*/
function startServer() {
console.log('🚀 Starting Express server...');
console.log('');
const serverProcess = spawn('node', ['server.js'], {
stdio: 'inherit', // Pipe output directly to console
env: process.env,
shell: true,
});
// Forward exit code from server process
serverProcess.on('close', (code) => {
console.log('');
console.log(`Server process exited with code ${code}`);
process.exit(code || 0);
});
// Handle termination signals (Railway sends SIGTERM for graceful shutdown)
process.on('SIGTERM', () => {
console.log('');
console.log('📡 Received SIGTERM signal, shutting down gracefully...');
serverProcess.kill('SIGTERM');
});
process.on('SIGINT', () => {
console.log('');
console.log('📡 Received SIGINT signal, shutting down gracefully...');
serverProcess.kill('SIGINT');
});
// Handle server process errors
serverProcess.on('error', (error) => {
console.error('');
console.error('❌ Failed to start server:', error.message || String(error));
console.error('');
process.exit(1);
});
}
/**
* Main execution flow
*
* Railway Production Behavior:
* 1. Runs migrations first (fail-safe: continues even if migrations fail)
* 2. Always starts the server (prevents restart loops)
* 3. Server will fail at runtime if there are critical database issues
* (better than infinite restart loop on Railway)
*/
async function main() {
try {
// Step 1: Attempt to run migrations
// Note: runMigrations() always resolves (never rejec3 months ago
move prisma from devdependencies to dependencies in your package.json
"dependencies": {
"prisma": "^6.x.x",
"@prisma/client": "^6.x.x"
}
then redeploy
dardameiz
move prisma from devdependencies to dependencies in your package.json"dependencies": {"prisma": "^6.x.x","@prisma/client": "^6.x.x"}then redeploy
3 months ago
I have moved it but still not working
3 months ago
Did you push the updated package.json? Try clearing Railway’s build cache, go to Service Settings - Deploy - Clear Build Cache, then redeploy. Also share what your dependencies section looks like now
dardameiz
Did you push the updated package.json? Try clearing Railway’s build cache, go to Service Settings - Deploy - Clear Build Cache, then redeploy. Also share what your dependencies section looks like now
3 months ago
I have package-lock.json do I need to remove it?
dardameiz
Did you push the updated package.json? Try clearing Railway’s build cache, go to Service Settings - Deploy - Clear Build Cache, then redeploy. Also share what your dependencies section looks like now
3 months ago
"dependencies": {
"@prisma/client": "^5.7.1",
"prisma": "^5.7.1",
"axios": "^1.6.2",
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"express-rate-limit": "^7.1.5",
"express-validator": "^7.0.1",
"helmet": "^7.1.0",
"jsonwebtoken": "^9.0.2",
"morgan": "^1.10.0",
"multer": "^2.0.2",
"socket.io": "^4.6.1"
3 months ago
Looks correct. What you can do is delete package-lock.json, run npm install locally to regenerate it, commit both files, then redeploy. If still failing, clear build cache in Railway service settings and redeploy again.
dardameiz
Looks correct. What you can do is delete package-lock.json, run npm install locally to regenerate it, commit both files, then redeploy. If still failing, clear build cache in Railway service settings and redeploy again.
3 months ago
I'm not locating the build cache
3 months ago
I meant: Go to Service, then Settings tab, scroll to Build section, click Clear Build Cache.
dardameiz
I meant: Go to Service, then Settings tab, scroll to Build section, click Clear Build Cache.
3 months ago
Just did and still giving me error.
I have package.json in my root directory do I need to delete it and keep the one in my backend?
samuelamofa
Just did and still giving me error.I have package.json in my root directory do I need to delete it and keep the one in my backend?
3 months ago
If you have prisma as a dev dep in your backend, you should also move it up to a regular dep.
Also, once you have done that, make sure to delete node_modules and the lockfile and run npm i to regenerate both. After, make sure to commit the new lockfile.
0x5b62656e5d
If you have prisma as a dev dep in your backend, you should also move it up to a regular dep.Also, once you have done that, make sure to delete node_modules and the lockfile and run npm i to regenerate both. After, make sure to commit the new lockfile.
3 months ago
I did that but still crushing
