Search code examples
undefinedpidchild-process

Node console.log(process.pid) prints undefined


I'm working on a project using Electron and Webpack in which I have three processes: main, renderer and app (app and renderer being children of main). App process is forked from main. Before applying webpack into app process, eveything worked just fine. Now that I'm using webpack to create app's bundle, suddenly the child process doesn't seem to be able to send messages to it's parent process.

While debugging, I've added the following line in app's file:

console.log(process.pid);

And weirdly it prints out undefined. How can a process print it's own PID and print undefined?

enter image description here


Solution

  • Silly mistake. In webpack.app.config.js file, target should be node, but it was electron-main. Changed it and everything worked.

    I still don't know why it printed undefined as it's PID, though.