2

Im trying to use nodemon with bable-node. I have this command in my package.json:

"open-graph-playground": "nodemon --exec babel-node src/graphql/mock-server.js",

This is the JavaScript file:

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');

When I run yarn open-graph-playground in my terminal it I get this error:

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.

The weird thing is that even though the process in the terminal has closed the server is up an running on http://localhost:4001/mock-graphql-playground

Evanss
  • 23,390
  • 94
  • 282
  • 505

2 Answers2

0

nodemon itself has hit the max open file descriptors resource limit. That causes nodemon to crash.

However, nodemon is forking to execute babel-node as another process. I suspect that when nodemon crashes, the babel-node process is still running. You should be able to check the output of ps (or ps -f, or whatever) and see that it is still running.

anthonyserious
  • 1,758
  • 17
  • 15
0

You might have hit the soft limit of file watches allowed by the operating system. But the server runs fine as file watches aren't integral to the server. File watches are used to reload the server when you change the source code. There are two reasons why this might happen.

1. Nodemon is watching files outside of the project

Due to your folder structure, nodemon maybe watching extra files such as your node_modules folder. Point nodemon to the correct directory by using --watch ./src

2. Your project contains more files than the watch limit

Some operating systems have a limit on how many files can be watched at a time. Your project or your environment may require watching more files than is allowed by the system. Changing this on linux is straight forward

sysctl -n -w fs.inotify.max_user_watches=16384

More info & source

Avin Kavish
  • 8,317
  • 1
  • 21
  • 36