nodemon - 带有 bable-node 的 nodemon 在终端崩溃但服务器运行良好?
问题描述
我正在尝试将 nodemon 与 bable-node 一起使用。我的 package.json 中有这个命令:
"open-graph-playground": "nodemon --exec babel-node src/graphql/mock-server.js",
这是 JavaScript 文件:
import fs from 'fs';
import open from 'open';
import { buildSchema } from 'graphql';
import express from 'express';
import graphqlHTTP from 'express-graphql';
import root from './root';
const schemaString = fs.readFileSync(`${__dirname}/schema.graphql`, 'utf8');
const app = express();
const schema = buildSchema(schemaString);
app.use(
'/mock-graphql-playground',
graphqlHTTP({
schema,
rootValue: root,
graphiql: true,
}),
);
app.listen(4001);
open('http://localhost:4001/mock-graphql-playground');
当我yarn open-graph-playground
在终端中运行时,我收到此错误:
yarn run v1.13.0
$ nodemon --exec babel-node src/graphql/mock-server.js
[nodemon] 1.18.10
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `babel-node src/graphql/mock-server.js`
2019-05-30 15:45 node[1683] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2019-05-30 15:45 node[1683] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
[nodemon] Internal watch failed: EMFILE: too many open files, watch
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
奇怪的是,即使终端中的进程已关闭,服务器仍在运行http://localhost:4001/mock-graphql-playground
解决方案
您可能已经达到操作系统允许的文件监视的软限制。但是服务器运行良好,因为文件监视不是服务器的组成部分。文件监视用于在您更改源代码时重新加载服务器。发生这种情况的原因有两个。
1.Nodemon正在监视项目外的文件
由于您的文件夹结构,nodemon 可能会查看额外的文件,例如您的node_modules
文件夹。通过使用将 nodemon 指向正确的目录--watch ./src
2.您的项目包含的文件多于观察限制
某些操作系统对一次可以查看的文件数量有限制。您的项目或您的环境可能需要观看比系统允许的更多的文件。在 linux 上更改它是直截了当的
sysctl -n -w fs.inotify.max_user_watches=16384
推荐阅读
- javascript - 访问仅客户端网站的本地文件,以 HTML 下载的形式分发,用户使用浏览器打开
- javascript - httpclient 响应中不存在 Set-Cookie
- css - Flask - 对 css 文件所做的更改不会反映在浏览器上
- python - 转换为_datetime 错误,无法识别的值类型
- php - 如何修复网址包含阿拉伯字符
- julia - Pkg的颜色和符号说明
- python - How do I create Conda environment in Windows 10
- excel - 获取 API 数据时“签名无效”(VBA-Excel)
- javascript - 查找和替换html中的空格
- three.js - Distorted mesh with bones