Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process.env undefined on few libs #2540

Closed
3l0w opened this issue Mar 21, 2020 · 10 comments
Closed

Process.env undefined on few libs #2540

3l0w opened this issue Mar 21, 2020 · 10 comments
Labels

Comments

@3l0w
Copy link

3l0w commented Mar 21, 2020

  • Version: 12.16.1 & 13.11.0

  • Platform: Linux ordi-msi 4.15.0-91-generic new design of error handling node#92-Ubuntu SMP Fri Feb 28 11:09:48 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

  • Subsystem:

What steps will reproduce the bug?

when i try to use a libs who use process.env.
I try with https://www.npmjs.com/package/fluent-ffmpeg
and https://www.npmjs.com/package/websocket

How often does it reproduce? Is there a required condition?

Every times on my laptop

What do you see instead?

With ffmpeg:

(node:3739) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'FFMPEG_PATH' of undefined
    at /home/fl0w/dev/spotifyBot/node_modules/fluent-ffmpeg/lib/capabilities.js:96:25
    at nextTask (/home/fl0w/dev/spotifyBot/node_modules/async/dist/async.js:4576:27)
    at Object.waterfall (/home/fl0w/dev/spotifyBot/node_modules/async/dist/async.js:4587:9)
    at Object.awaitable [as waterfall]

https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/lib/capabilities.js#L96
With webSocket:

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at Object.<anonymous> (/home/fl0w/dev/spotifyBot/node_modules/websocket/node_modules/debug/src/node.js:33:30)

https://github.com/visionmedia/debug/blob/master/src/node.js#L120

Additional information

Output of console.log(process.env) in the main file of my project is not undefined and has all env variable define.

EDIT: also does it on my vps : Linux ubuntu 18.04 with node v12.4.0
@cjihrig cjihrig transferred this issue from nodejs/node Mar 21, 2020
@addaleax
Copy link
Member

You could try to add a setter for process.env that logs a stack trace, that probably helps with figuring out why this is happening, e.g.

{
  let env = process.env;
  Object.defineProperty(process, 'env', {
    enumerable: true,
    get() { return env; },
    set(v) { console.trace('process.env is being set here'); env = v; }
  });
}

@3l0w
Copy link
Author

3l0w commented Mar 21, 2020

Thanks for you response but where i put this code?

@addaleax
Copy link
Member

@3l0w Somewhere where there’s code that’s running while process.env is still intact. If necessary, save if in a different file and then start Node.js with --require /path/to/that/file.js, that way it will run even before the main script.

@3l0w
Copy link
Author

3l0w commented Mar 21, 2020

image
that all i got...

@addaleax
Copy link
Member

@3l0w --require is a Node.js option, not an option of your script, so it needs to go before the main script’s name, i.e. node --require process.js index.js

@3l0w
Copy link
Author

3l0w commented Mar 21, 2020

image

@addaleax
Copy link
Member

Okay, then I don’t quite know what’s happening. Is process itself being overridden somewhere?

(You can check using the same code as above, except with process replaced with global and env replaced with process)

@3l0w
Copy link
Author

3l0w commented Mar 21, 2020

I try some test:
when i console.log(process.env) my env is display.
and i remove nvm from my computer and now ffmpeg work but websocket send same error

@github-actions
Copy link

There has been no activity on this issue for 3 years and it may no longer be relevant. It will be closed 1 month after the last non-automated comment.

@github-actions github-actions bot added the stale label Mar 22, 2023
@github-actions
Copy link

There has been no activity on this issue and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants