我是 Next Js 的新手。我目前安装了 supervisor 来监视文件的变化,因为 nodemon 似乎不能正常工作。它有时起作用,有时不起作用。当它工作时,我总是必须在运行 npm run dev 之前运行 npm install。
当它不起作用时,这就是我得到的
当它工作时,在我运行 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 文件夹,不确定这是否对这个问题有任何影响。