【问题标题】:Nodemon stuck at restarting due to changes for Next.js由于 Next.js 的更改,Nodemon 卡在重新启动
【发布时间】:2021-10-02 07:50:38
【问题描述】:

由于更改,我的 nodemon 一直卡在重新启动。我目前正在使用 Next.js 框架。我已经尝试安装和卸载 nodemon 但它不起作用。

以下是我的 package.json

{
  "name": "next_js_proj",
  "version": "0.1.0",
  "private": false,
  "scripts": {
    "dev": "nodemon server.js",
    "build": "next build",
    "start": "NODE_ENV=production node server.js"
  },
  "dependencies": {
    "@artsy/fresnel": "^1.2.2",
    "axios": "^0.21.0",
    "bcryptjs": "^2.4.3",
    "cors": "^2.8.5",
    "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",
    "uuid": "^8.2.0",
    "validator": "^13.0.0"
  }
}

服务器.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;

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(`Hello, Express server running on ${PORT}`);
    });
});

一开始我启动服务器时,它可以工作

我做了后续更改后,它不起作用

请多指教,万分感谢

【问题讨论】:

  • 我们遇到了同样的问题。自上周以来没有任何改变。
  • @KiprasT 所以你也有同样的问题吗?
  • 你有 nodemon 配置文件吗?如果有,它是什么样子的?
  • 没关系,我解决了,谢谢

标签: node.js reactjs npm next.js nodemon


【解决方案1】:

这就是我在下一个 js 中解决这个 nodemon 问题的方法。

一个。我在 2.0.7 的 dev 依赖项中下载了 nodemon 。似乎较新的版本在我的本地造成了问题。

b.更新 package.json 中的脚本

  "scripts": {
    "dev": "nodemon server.js",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  }

c。在根目录下创建nodemon.json

{
    "verbose": true,
    "ignore": [
        "node_modules",
        ".next"
    ],
    "watch": [
        "server/**/*",
        "server.js",
        "api/",
        "validators/",
        "models/"
    ],
    "ext": "js json"
}

Nodemon 当前正在监视 server.js , api 文件夹中的文件等。如果您希望 nodemon 监视任何其他文件夹,只需将其添加到 watch 数组中。因此,如果您希望 nodemon 监视目录调用 foo 中的文件,只需将其 nodemon.js 更新为以下内容

{
    "verbose": true,
    "ignore": [
        "node_modules",
        ".next"
    ],
    "watch": [
        "server/**/*",
        "server.js",
        "api/",
        "validators/",
        "models/",
        "foo/"
    ],
    "ext": "js json"
}

d。运行 npm dev,它应该可以工作了。

【讨论】:

    猜你喜欢
    • 2019-03-23
    • 2020-07-16
    • 2021-11-05
    • 2018-07-10
    • 2022-11-24
    • 2020-08-21
    • 2020-06-15
    • 1970-01-01
    相关资源
    最近更新 更多