-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
💻
- Would you like to work on a fix?
How are you using Babel?
@babel/register or @babel/node
Input code
process.on('message', () => {});
... or run the widely-used exit-hook
library:
const exitHook = require('exit-hook'); // version >= 2.0.0 with PM2 shutdown message hook
exitHook(() => {
console.log('exit');
});
Configuration file name
No response
Configuration
No response
Current and expected behavior
The script is expected to exit but hangs instead. When running the same script with node
instead of babel-node
, it exits.
Environment
- Babel version: 7.13.16, (
@babel/node
at 7.13.13) - Node: 12
Possible solution
The issue seems to be that when running babel-node
, an IPC channel is always set up on this line in babel-node.js
.
Node docs state the following regarding the IPC channel:
It is worth noting that when an IPC channel is established between the parent and child processes, and the child is a Node.js process, the child is launched with the IPC channel unreferenced (using unref()) until the child registers an event handler for the 'disconnect' event or the 'message' event. This allows the child to exit normally without the process being held open by the open IPC channel.
Conversely, if an event handler is added, then the child refuses to exit until disconnected. This causes behavior of the same script to differ when run in babel-node
compared to regular node
.
Ideally, the IPC channel would only be set up when needed, which is when the babel-node
process itself has an IPC channel. Thus, only adding the "ipc"
argument when process.send != null
in the parent process should do the trick.
Additional context
No response