在 Linux 上运行 nodemon 的问题

在 Linux 上运行 nodemon 的问题

我正在运行 Linux Mint 19.2 双启动和 Windows。我有一个项目,其中我使用 nodemon 重新启动运行 nextjs 应用程序的节点服务器。它在 Windows 上运行良好,但在 Linux 上存在一些问题。

首先,当我关闭终端(集成终端或 vscode)时,nodemon 进程不会终止。因此,当我再次打开终端或 vscode 后尝试重新启动应用程序时,仍然有一个进程在端口 3000 上运行,所以我必须终止该进程才能重新启动服务器。

下一个问题是,当我编辑并保存文件时,服务器尝试重新启动,但随后出现错误,提示不存在这样的文件。我使用已安装存储驱动器上的文件,但我不知道为什么会发生这种情况。这非常令人沮丧。

这是我得到的错误

[nodemon] restarting due to changes...
[nodemon] starting `node app.js`
(node:3440) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, rmdir '/media/steveK/Storage Drive/Web Pages/React Apps/Full Stack/project/.next/cache/next-babel-loader'
(node:3440) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3440) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[nodemon] clean exit - waiting for changes before restart

这是 app.js

const express = require('express');
const next = require('next');
const PORT = process.env.PORT || 3000;
const dev = process.env.NODE_DEV !== 'production';
const nextApp = next({ dev });
const handle = nextApp.getRequestHandler();
const app = express();

nextApp.prepare().then(() => {
  app.get('*', (req, res) => {
    return handle(req, res);
  });

  app.listen(PORT, err => {
    if (err) throw err;
    console.log(`ready at http://localhost:${PORT}`);
  });
});

我曾尝试使用nodemon -L app.js但这也无济于事。

有没有其他人在 Linux 上运行 nodemon 时遇到问题?如果是这样,也许你可以告诉我如何解决这个问题。

相关内容