Repository navigation
child_process.fork not passing along options.env #20749
Description
Activity
Try:
require('child_process').fork('./child.js', [], { env: { FOO: 'bar' } });
@nodejs/child_process Is this expected behavior that the second argument set in
undefinedornullprevents the third one from being transferred?Reacted by George Borisov and Martynas Žilinskas- addedchild_processIssues and PRs related to the child_process subsystem.Issues and PRs related to the child_process subsystem.
on May 15, 2018 @vsemozhetbyt thanks - this also works:
require('child_process').fork('./child.js', { env: { FOO: 'bar' } });I can guess why this is happening, having seen enough dodgy JS code that does parameter overloading ;)
Reacted by Vse Mozhe Buty, Rocky Warren and Martynas Žilinskas@vsemozhetbyt I think the check for arguments can be improved.
Line 73 in 7f0f978
if (pos < arguments.length && arguments[pos] != null) { Line 74 in 7f0f978
if (typeof arguments[pos] !== 'object') { We can check for emptiness (something like
lodash.isEmpty) for both of the arguments. Then we can conditionally check whether both are present or not.Or we can just document the behavior altogether. 😛
This looks like an ambiguity problem, and improving docs seems to be the logical way forward to me as well.
As a developer, even if documented, this looks like broken behaviour. Throwing an error on an invalid argument type is perfectly acceptable, but ignoring the subsequent argument is just shoddy - to be tolerated in a third party lib but not a core Node module. Just my opinion.
Reacted by Morris Allison III and Torsten Severing@borisovg if you insist, I could look a tad deeper into this over the course of the next few days and hack up a small PR.
2 remaining items
- added 6 commits that reference this issue
on Aug 20, 2018 - added a commit that references this issue
on Nov 2, 2018 - added a commit that references this issue
on Nov 2, 2018 - added 2 commits that reference this issue
on Nov 27, 2018 - added 2 commits that reference this issue
on Nov 28, 2018 - added 2 commits that reference this issue
on Nov 29, 2018
parent.js:
child.js
output: