Правильный способ настройки Supervisor с Next JS
Я новичок в Next Js. В настоящее время я установил супервизор, чтобы следить за изменениями в файлах, потому что nodemon, похоже, не работает. Иногда это работает, а иногда нет. Когда он работает, мне всегда нужно запускать npm install перед запуском npm run dev.
Когда не работает, вот что я получаю
Когда он работает, после запуска npm install
Это мой package.json
{
"name": "my-project",
"version": "0.1.0",
"private": false,
"scripts": {
"dev": "supervisor server.js",
"start": "cross-env NODE_ENV=production supervisor server.js",
"build": "next build"
},
"dependencies": {
"@artsy/fresnel": "^1.2.2",
"axios": "^0.21.0",
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"cross-env": "^7.0.3",
"crypto": "^1.0.1",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"js-cookie": "^2.2.1",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.15",
"moment": "^2.24.0",
"mongoose": "^5.9.14",
"morgan": "^1.10.0",
"next": "^10.0.3",
"nodemailer": "^6.4.8",
"nodemon": "^2.0.7",
"nodemailer-sendgrid-transport": "^0.2.0",
"nookies": "^2.3.0",
"nprogress": "^0.2.0",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-infinite-scroll-component": "6.0.0",
"react-moment": "^0.9.7",
"react-toastify": "^6.0.5",
"semantic-ui-css": "^2.4.1",
"semantic-ui-react": "^2.0.0",
"socket.io": "^2.3.0",
"socket.io-client": "^2.3.0",
"supervisor": "^0.12.0",
"uuid": "^8.2.0",
"validator": "^13.0.0"
},
"devDependencies": {
"cross-env": "^7.0.3",
"supervisor": "^0.12.0"
}
}
Это мой файл server.js
const express = require("express");
const app = express();
const server = require("http").Server(app);
const next = require("next");
const dev = process.env.NODE_ENV !== "production";
const nextApp = next({ dev });
const handle = nextApp.getRequestHandler();
require("dotenv").config({ path: "./config.env" });
const connectDb = require("./utilsServer/connectDb");
connectDb();
app.use(express.json());
const PORT = process.env.PORT || 3000;
console.log('starting up ++++')
nextApp.prepare().then(() => {
app.use("/api/signup", require("./api/signup"));
app.use("/api/auth", require("./api/auth"));
app.all("*", (req, res) => handle(req, res));
server.listen(PORT, err => {
if (err) throw err;
console.log(`express app detect changes, Express server running on ${PORT}`);
});
});
Пожалуйста, посоветуйте, спасибо. РЕДАКТИРОВАТЬ: Я также помещаю папку api в корневой каталог, не уверен, повлияет ли это на эту проблему.