20 days ago
My project is frontend react based, backend nodeJs based and db is MySQL remotely used of hostinger. I wanted to test the final product but deployment crashes with these redundant errors:
sh: 1: nodemon: not found
sh: 1: vite: not found
I used
build command: npm run build
Start command: npm run start
What is the underlying reason to it. Help me get thorugh it.
7 Replies
20 days ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
20 days ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open brody • 20 days ago
20 days ago
{
"scripts": {
"dev": "nodemon server.js",
"start": "node server.js", // must use "node" rather than nodemon
"build": "vite build",
"preview": "vite preview"
}
}
In your package.json, make sure that you are using node for the start command (instead of nodemon). The above scripts should work for you. Before trying that out, can you please provide the package.json file that you have in your project?
If that did not help, you can install a small package named serve & use it to start the server. The scripts object would look like this then:
npm install serve
{
"scripts": {
"dev": "vite", // for local dev only
"build": "vite build", // builds static assets
"start": "serve -s dist" // serves the production build
}
}
Make sure to change file file name, according to your directory
20 days ago
Nodemon & Vite are dev dependencies
nodemon = used only in development to auto-restart Node backend.
vite = used only to serve the React frontend in dev mode.
In production, these aren't supposed to run.
Your start script is pointing to dev tools
If your package.json has something like this,
That works locally but fails in deployment, because the server doesn’t install dev dependencies (nodemon, vite) unless you force it.
In production, you should serve,
React build (npm run build → dist/ or build/ folder).
Node.js backend (node server.js or whatever your entry is).
You don’t run vite or nodemon.
so here is how to fix it
first, fix your scripts in package.json
Update so you have separate dev vs prod scripts:
"scripts": {
"start": "nodemon server.js",
"dev": "vite"
}
"scripts": {
"dev": "concurrently \"npm run dev:server\" \"npm run dev:client\"",
"dev:server": "nodemon server.js",
"dev:client": "vite",
"build": "cd client && npm run build",
"start": "node server.js"
}
dev - runs nodemon + vite locally.
build - builds frontend.
start - runs backend only (serving frontend’s static files).
second, serve React build from Node backend
In your server.js (Node backend), after building React:
import express from "express";
import path from "path";
const app = express();
// Serve frontend
const __dirname = path.resolve();
app.use(express.static(path.join(__dirname, "client/dist")));
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "client/dist/index.html"));
});
// Your API routes...
app.listen(5000, () => console.log("Server running on port 5000"));
Latly, Deploy properly
Run npm run build (this builds frontend).
Deployment host should run npm start -> node server.js, not nodemon or vite.
clashing
{ "scripts": { "dev": "nodemon server.js", "start": "node server.js", // must use "node" rather than nodemon "build": "vite build", "preview": "vite preview" } }In your package.json, make sure that you are using node for the start command (instead of nodemon). The above scripts should work for you. Before trying that out, can you please provide the package.json file that you have in your project?If that did not help, you can install a small package named serve & use it to start the server. The scripts object would look like this then:npm install serve{ "scripts": { "dev": "vite", // for local dev only "build": "vite build", // builds static assets "start": "serve -s dist" // serves the production build } }Make sure to change file file name, according to your directory
20 days ago
I am providing you with my package.json file. Can you please tell me what to add to which file?
frontend package.json :
{
"name": "mern-template-frontend",
"version": "0.1.0",
"private": true,
"type": "module",
"dependencies": {
"axios": "^1.5.0",
"chart.js": "^4.5.0",
"html2canvas": "^1.4.1",
"qrcode": "^1.5.4",
"react": "^18.2.0",
"react-chartjs-2": "^5.3.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.15.0",
"uuid": "^11.1.0"
},
"devDependencies": {
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@vitejs/plugin-react": "^4.6.0",
"eslint": "^8.45.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"vite": "^4.5.14"
},
"scripts": {
"dev": "vite",
"build": "vite build",
"start": "serve -s dist",
"preview": "vite preview",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0"
}
}
backend package.json:
{
"name": "indians-in-ghana-backend",
"version": "1.0.0",
"description": "Backend API for Indians in Ghana Membership System",
"main": "server.js",
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js",
"test": "jest"
},
"dependencies": {
"axios": "^1.10.0",
"bcryptjs": "^2.4.3",
"compression": "^1.7.4",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"express-mysql-session": "^3.0.3",
"express-rate-limit": "^6.10.0",
"express-session": "^1.18.1",
"express-validator": "^7.2.1",
"helmet": "^7.0.0",
"jsonwebtoken": "^9.0.2",
"multer": "^1.4.5-lts.1",
"mysql2": "^3.14.3",
"node-fetch": "^3.3.2",
"nodemailer": "^6.9.5"
},
"devDependencies": {
"jest": "^29.7.0",
"nodemon": "^3.1.10",
"supertest": "^6.3.3"
},
"keywords": [
"membership",
"community",
"ghana",
"indian",
"mern"
],
"author": "Indians in Ghana",
"license": "ISC"
}
root package.json:
{
"name": "mern-template",
"version": "1.0.0",
"description": "A minimal MERN stack template with authentication",
"main": "index.js",
"scripts": {
"dev": "concurrently \"npm run server\" \"npm run client\"",
"server": "cd backend && npm run dev",
"client": "cd frontend && npm run dev",
"build": "cd backend && npm install && cd ../frontend && npm install && npm run build",
"start": "cd backend && npm run start & cd ../frontend && npm run start",
"install-all": "npm install && cd backend && npm install && cd ../frontend && npm install"
},
"keywords": [
"mern",
"react",
"nodejs",
"express",
"mongodb",
"template"
],
"author": "",
"license": "MIT",
"devDependencies": {
"concurrently": "^8.2.2",
"kill-port": "^2.0.1"
},
"dependencies": {
"axios": "^1.11.0",
"dotenv": "^17.2.1",
"mysql2": "^3.14.3",
"node-fetch": "^2.7.0",
"serve": "^14.2.4",
"uuid": "^11.1.0"
}
}
david-davidson-arch
Nodemon & Vite are dev dependencies nodemon = used only in development to auto-restart Node backend. vite = used only to serve the React frontend in dev mode. In production, these aren't supposed to run. Your start script is pointing to dev tools If your package.json has something like this, That works locally but fails in deployment, because the server doesn’t install dev dependencies (nodemon, vite) unless you force it. In production, you should serve, React build (npm run build → dist/ or build/ folder). Node.js backend (node server.js or whatever your entry is). You don’t run vite or nodemon. so here is how to fix it first, fix your scripts in package.json Update so you have separate dev vs prod scripts: "scripts": { "start": "nodemon server.js", "dev": "vite" } "scripts": { "dev": "concurrently \"npm run dev:server\" \"npm run dev:client\"", "dev:server": "nodemon server.js", "dev:client": "vite", "build": "cd client && npm run build", "start": "node server.js" } dev - runs nodemon + vite locally. build - builds frontend. start - runs backend only (serving frontend’s static files). second, serve React build from Node backend In your server.js (Node backend), after building React: import express from "express"; import path from "path"; const app = express(); // Serve frontend const __dirname = path.resolve(); app.use(express.static(path.join(__dirname, "client/dist"))); app.get("*", (req, res) => { res.sendFile(path.join(__dirname, "client/dist/index.html")); }); // Your API routes... app.listen(5000, () => console.log("Server running on port 5000")); Latly, Deploy properly Run npm run build (this builds frontend). Deployment host should run npm start -> node server.js, not nodemon or vite.
20 days ago
I am providing you with my package.json file. Can you please tell me what to add to which file?
frontend package.json :
{
"name": "mern-template-frontend",
"version": "0.1.0",
"private": true,
"type": "module",
"dependencies": {
"axios": "^1.5.0",
"chart.js": "^4.5.0",
"html2canvas": "^1.4.1",
"qrcode": "^1.5.4",
"react": "^18.2.0",
"react-chartjs-2": "^5.3.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.15.0",
"uuid": "^11.1.0"
},
"devDependencies": {
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@vitejs/plugin-react": "^4.6.0",
"eslint": "^8.45.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"vite": "^4.5.14"
},
"scripts": {
"dev": "vite",
"build": "vite build",
"start": "serve -s dist",
"preview": "vite preview",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0"
}
}
backend package.json:
{
"name": "indians-in-ghana-backend",
"version": "1.0.0",
"description": "Backend API for Indians in Ghana Membership System",
"main": "server.js",
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js",
"test": "jest"
},
"dependencies": {
"axios": "^1.10.0",
"bcryptjs": "^2.4.3",
"compression": "^1.7.4",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"express-mysql-session": "^3.0.3",
"express-rate-limit": "^6.10.0",
"express-session": "^1.18.1",
"express-validator": "^7.2.1",
"helmet": "^7.0.0",
"jsonwebtoken": "^9.0.2",
"multer": "^1.4.5-lts.1",
"mysql2": "^3.14.3",
"node-fetch": "^3.3.2",
"nodemailer": "^6.9.5"
},
"devDependencies": {
"jest": "^29.7.0",
"nodemon": "^3.1.10",
"supertest": "^6.3.3"
},
"keywords": [
"membership",
"community",
"ghana",
"indian",
"mern"
],
"author": "Indians in Ghana",
"license": "ISC"
}
root package.json:
{
"name": "mern-template",
"version": "1.0.0",
"description": "A minimal MERN stack template with authentication",
"main": "index.js",
"scripts": {
"dev": "concurrently \"npm run server\" \"npm run client\"",
"server": "cd backend && npm run dev",
"client": "cd frontend && npm run dev",
"build": "cd backend && npm install && cd ../frontend && npm install && npm run build",
"start": "cd backend && npm run start & cd ../frontend && npm run start",
"install-all": "npm install && cd backend && npm install && cd ../frontend && npm install"
},
"keywords": [
"mern",
"react",
"nodejs",
"express",
"mongodb",
"template"
],
"author": "",
"license": "MIT",
"devDependencies": {
"concurrently": "^8.2.2",
"kill-port": "^2.0.1"
},
"dependencies": {
"axios": "^1.11.0",
"dotenv": "^17.2.1",
"mysql2": "^3.14.3",
"node-fetch": "^2.7.0",
"serve": "^14.2.4",
"uuid": "^11.1.0"
}
}
vidsht
I am providing you with my package.json file. Can you please tell me what to add to which file?frontend package.json :{ "name": "mern-template-frontend", "version": "0.1.0", "private": true, "type": "module", "dependencies": { "axios": "^1.5.0", "chart.js": "^4.5.0", "html2canvas": "^1.4.1", "qrcode": "^1.5.4", "react": "^18.2.0", "react-chartjs-2": "^5.3.0", "react-dom": "^18.2.0", "react-router-dom": "^6.15.0", "uuid": "^11.1.0" }, "devDependencies": { "@types/react": "^18.2.15", "@types/react-dom": "^18.2.7", "@vitejs/plugin-react": "^4.6.0", "eslint": "^8.45.0", "eslint-plugin-react": "^7.32.2", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-refresh": "^0.4.3", "vite": "^4.5.14" }, "scripts": { "dev": "vite", "build": "vite build", "start": "serve -s dist", "preview": "vite preview", "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0" } }backend package.json:{ "name": "indians-in-ghana-backend", "version": "1.0.0", "description": "Backend API for Indians in Ghana Membership System", "main": "server.js", "scripts": { "start": "node server.js", "dev": "nodemon server.js", "test": "jest" }, "dependencies": { "axios": "^1.10.0", "bcryptjs": "^2.4.3", "compression": "^1.7.4", "cors": "^2.8.5", "dotenv": "^16.3.1", "express": "^4.18.2", "express-mysql-session": "^3.0.3", "express-rate-limit": "^6.10.0", "express-session": "^1.18.1", "express-validator": "^7.2.1", "helmet": "^7.0.0", "jsonwebtoken": "^9.0.2", "multer": "^1.4.5-lts.1", "mysql2": "^3.14.3", "node-fetch": "^3.3.2", "nodemailer": "^6.9.5" }, "devDependencies": { "jest": "^29.7.0", "nodemon": "^3.1.10", "supertest": "^6.3.3" }, "keywords": [ "membership", "community", "ghana", "indian", "mern" ], "author": "Indians in Ghana", "license": "ISC" }root package.json:{ "name": "mern-template", "version": "1.0.0", "description": "A minimal MERN stack template with authentication", "main": "index.js", "scripts": { "dev": "concurrently \"npm run server\" \"npm run client\"", "server": "cd backend && npm run dev", "client": "cd frontend && npm run dev", "build": "cd backend && npm install && cd ../frontend && npm install && npm run build", "start": "cd backend && npm run start & cd ../frontend && npm run start", "install-all": "npm install && cd backend && npm install && cd ../frontend && npm install" }, "keywords": [ "mern", "react", "nodejs", "express", "mongodb", "template" ], "author": "", "license": "MIT", "devDependencies": { "concurrently": "^8.2.2", "kill-port": "^2.0.1" }, "dependencies": { "axios": "^1.11.0", "dotenv": "^17.2.1", "mysql2": "^3.14.3", "node-fetch": "^2.7.0", "serve": "^14.2.4", "uuid": "^11.1.0" } }
19 days ago
Your root start script is doing this:
"start": "cd backend && npm run start & cd ../frontend && npm run start"
That means in production it tries to run both:
npm run start inside backend -> runs node server.js
npm run start inside frontend -> runs serve -s dist
The error sh: 1: nodemon: not found and sh: 1: vite: not found happen because:
nodemon is only in devDependencies of backend -> not installed in production.
vite is only in devDependencies of frontend -> not installed in production.
But you dont even want to run those in production. In prod:
Backend should run node server.js.
Frontend should be pre-built (npm run build -> creates dist/).
Backend should serve frontends static files (not vite, not serve).
to change
1) Backend (backend/server.js)
Make sure your backend serves the frontend’s build folder:
import express from "express";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
// API routes here
// app.use("/api", yourRoutes);
// Serve frontend
app.use(express.static(path.join(__dirname, "../frontend/dist")));
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "../frontend/dist/index.html"));
});
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
2) Frontend (frontend/package.json)
Keep it minimal. You don’t need start in production (the backend serves it).
Change scripts to:
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
}
(remove "start": "serve -s dist" because we’ll never use it in prod)
3) Root package.json
Fix scripts like this:
"scripts": {
"dev": "concurrently \"npm run server\" \"npm run client\"",
"server": "cd backend && npm run dev",
"client": "cd frontend && npm run dev",
"build": "cd frontend && npm install && npm run build",
"start": "cd backend && npm run start",
"install-all": "npm install && cd backend && npm install && cd ../frontend && npm install"
}
Now:
npm run dev -> runs backend (nodemon) + frontend (vite) locally for development.
npm run build -> builds frontend into frontend/dist.
npm start -> starts backend, which will also serve the built frontend.
david-davidson-arch
Your root start script is doing this: "start": "cd backend && npm run start & cd ../frontend && npm run start" That means in production it tries to run both: npm run start inside backend -> runs node server.js npm run start inside frontend -> runs serve -s dist The error sh: 1: nodemon: not found and sh: 1: vite: not found happen because: nodemon is only in devDependencies of backend -> not installed in production. vite is only in devDependencies of frontend -> not installed in production. But you dont even want to run those in production. In prod: Backend should run node server.js. Frontend should be pre-built (npm run build -> creates dist/). Backend should serve frontends static files (not vite, not serve). to change 1) Backend (backend/server.js) Make sure your backend serves the frontend’s build folder: import express from "express"; import path from "path"; import { fileURLToPath } from "url"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const app = express(); // API routes here // app.use("/api", yourRoutes); // Serve frontend app.use(express.static(path.join(__dirname, "../frontend/dist"))); app.get("*", (req, res) => { res.sendFile(path.join(__dirname, "../frontend/dist/index.html")); }); const PORT = process.env.PORT || 5000; app.listen(PORT, () => console.log(`Server running on port ${PORT}`)); 2) Frontend (frontend/package.json) Keep it minimal. You don’t need start in production (the backend serves it). Change scripts to: "scripts": { "dev": "vite", "build": "vite build", "preview": "vite preview" } (remove "start": "serve -s dist" because we’ll never use it in prod) 3) Root package.json Fix scripts like this: "scripts": { "dev": "concurrently \"npm run server\" \"npm run client\"", "server": "cd backend && npm run dev", "client": "cd frontend && npm run dev", "build": "cd frontend && npm install && npm run build", "start": "cd backend && npm run start", "install-all": "npm install && cd backend && npm install && cd ../frontend && npm install" } Now: npm run dev -> runs backend (nodemon) + frontend (vite) locally for development. npm run build -> builds frontend into frontend/dist. npm start -> starts backend, which will also serve the built frontend.
19 days ago
Formatting of your reply is very colorful, interesting