Welcome to the Linux Foundation Forum!

Troubles with ch-15 \ lab 1

I feel like I understand the ask, but I've honestly tried multiple runs (I'm on windows 10 BTW).

For the spawnSync, I've tried, what I feel like are, all variations where I assign options to be:

{ env: { MY_ENV_VAR: myEnvVar }}

However, every time it runs, I get every process environment variable; including the value supplied from test.ts and injected into the index method argument of myEnvVar.

I honestly don't know if this is a windows environment issue with Node, or a bad test (not accounting for how it works with windows), or I am doing it wrong. Who knows, it could even be all of them :(

Please, what am I doing wrong here?


P.s. I tried to be short on the answer.


  • kellvkellv Posts: 14

    I just tried this out on a mac and I found out it passes. This lab should be re-evaluated for windows environments.

  • Hey @kellv thanks for feeding back. All of the labs were written to work on windows, but this one is especially tricky to validate as OS's have a habit of injecting env vars into child processes. I need more info about what's going wrong, but I suspect there's an env var being injected unexpectedly by Windows - this could even be happening based on a particular way your OS is configured.

    are you using cmd or powershell?

    would you mind modifying the child.js so that on line 2 (just under 'use strict') you have:

    return console.log(process.env)

    and then run the following command:

    node -e "child_process.spawn(process.execPath, ['child.js'], {stdio: 'inherit', env: {}})"

    and paste the output here?

  • kellvkellv Posts: 14

    Hi David,

    Thanks for responding here.

    The local setup on window is powershell using nvs use 12
    When doing the argument injection I originally mentioned above, it is appending the property value to the already existing env vars object, which in itself is rather interesting.

    My findings were from altering the file by adding a console log for env similarly like you mentioned above as I was trying to debug my frustrations :)

    I'll go back through and do the following above with your node -e execution later. (I'm back into studying mode again).

  • kellvkellv Posts: 14

    @davidmarkclements I just ran your command in powershell and it I get:

    AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
    + actual - expected
    + undefined
    - 'is set'
        at Object.<anonymous> (C:\Users\kelly\jsnad\Labs-2020-06-07\ch-15\labs-1\child.js:9:8)
        at Module._compile (internal/modules/cjs/loader.js:1138:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
        at Module.load (internal/modules/cjs/loader.js:986:32)
        at Function.Module._load (internal/modules/cjs/loader.js:879:14)
        at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
        at internal/main/run_main_module.js:17:47 {
      generatedMessage: true,
      code: 'ERR_ASSERTION',
      actual: undefined,
      expected: 'is set',
      operator: 'strictEqual'

    So. it looks like that works as expected

  • hey @kellv can you make sure to modify child.js so line two is exactly:

    return console.log(process.env)

    and then run the command

    I want to exit early (return) and log out the env

  • kellvkellv Posts: 14
    edited September 2020

    As you officially requested sir. (and again, thank you) :)

      HOMEDRIVE: 'C:',
      HOMEPATH: '\\Users\\kelly',
      PATH: 'C:\\Users\\kelly\\AppData\\Local\\nvs\\node\\12.18.0\\x64;C:\\Python38\\Scripts\\;C:\\Python38\\;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\
    \System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\ProgramData\\chocolatey\\bin;C:\\Program Files\\dotnet\\;C:\\Program Files\\Git\\cmd;C:\\Users\\kelly\\App
    Data\\Local\\Microsoft\\WindowsApps;C:\\Users\\kelly\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\kelly\\AppData\\Local\\JetBrains;C:\\Users\\kelly\\AppData\\Local\
      SYSTEMDRIVE: 'C:',
      TEMP: 'C:\\Users\\kelly\\AppData\\Local\\Temp',
      USERNAME: 'kelly',
      USERPROFILE: 'C:\\Users\\kelly',

    And to add, I get the same results running in powershell and cmd

  • Hey, got the same thing. Works on mac , not on windows. Error received: "child process should only have one env var".

  • hey @kellv to get that output did you run

    node -e "child_process.spawn(process.execPath, ['child.js'], {stdio: 'inherit', env: {}})"


    node child.js

Sign In or Register to comment.