You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot disable warnings when node is launched via a shell script. #10802
As an end-user, I don't want to ever see warnings or deprecations. However, when node is invoked from a shell script via a shebang, there is no opportunity to pass the --no-warnings option to the process.
#!/usr/bin/env node --no-warnings
console.log("you will never get this far, so it doesn't matter if this compiles");
Is there an environment variable that can be set to toggle this option? If not, please add support for something like NODE_NO_WARNINGS=1.
changed the title [-]Cannot disable warnings when scripts are launched from the shell.[/-][+]Cannot disable warnings when node is launched via a shell script.[/+]on Jan 14, 2017
Which node version are you testing on? I'm testing fs.promises on node 10.16.0. The module doesn't emit a warning in v12.13.0 though because I believe it's no longer experimental.
@hexrcs the above works for me on Node 12. I have right before a process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; and this doesn't trigger a warning (while it does when NODE_NO_WARNINGS is not defined).
Weird, because setting it to either a string "1" or number 1 doesn't work on node v10 on my system (MacOS 10.14.6). (I was requiring the fs.promises module.)
Just tested on node v12.13.0 using the example below, also doesn't seem to work. :(
@hexrcs something which you can try is to spawn a child process after the env variable has been updated. I remember doing that on previous versions of node when using commander to create a node-based CLI tool.
I raised this same issue here (oops): #32876 and @sam-github kindly took the time to explain there's a solution using process.removeAllListeners('warning').
Reacted by Vladimir Panchenko, Radek Stepan, Kadar Claudiu, Peter Evans, grkblood13, Renato Oliveira, 宇果, Jeff Hall, Gyubong Lee, Ilia Choly and 14 more
Reacted by Zaghar, Leo Vo, Ilia Choly, brandon flowers, Bryce Carr, Jānis Blaus, Shivam, Pkmmte Xeleon and Jyotirmoy Bandyopadhayaya
Reacted by Peter Evans, Zaghar, sandboxcmd, Ilia Choly, Bryce Carr, Brian McCann, Jānis Blaus, Kees C. Bakker, Shivam, Kyle Pittman and 3 more
Activity
[-]Cannot disable warnings when scripts are launched from the shell.[/-][+]Cannot disable warnings when node is launched via a shell script.[/+]process: add NODE_NO_WARNINGS environment variable
process: add NODE_NO_WARNINGS environment variable
process: add NODE_NO_WARNINGS environment variable
process: add NODE_NO_WARNINGS environment variable
process: add NODE_NO_WARNINGS environment variable
process: add NODE_NO_WARNINGS environment variable
mnpenner commentedon Feb 5, 2019
What's the solution?
When I try putting this at the top of my file:
I just get:
bnoordhuis commentedon Feb 5, 2019
@mnpenner https://unix.stackexchange.com/questions/399690/multiple-arguments-in-shebang
Doragd commentedon Mar 14, 2019
@mnpenner
like this:
it works. :)
mnpenner commentedon Mar 14, 2019
@Doragd Huh? How would that work... the file contains JavaScript, it'll syntax error on
export NODE_NO_WARNINGS=18 remaining items
benjamingr commentedon Sep 18, 2019
@jasnell one issue I just noticed is that that can't be set from within the program when it has already launched.
SteveDeWald commentedon Jan 12, 2020
@benjamingr, are you able to put it in the shebang? This worked for me:
squallstar commentedon Jan 15, 2020
This also worked for me:
hexrcs commentedon Jan 16, 2020
@squallstar doesn't work for me.
Which node version are you testing on? I'm testing
fs.promiseson node 10.16.0. The module doesn't emit a warning in v12.13.0 though because I believe it's no longer experimental.squallstar commentedon Jan 16, 2020
@hexrcs the above works for me on Node 12. I have right before a
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';and this doesn't trigger a warning (while it does whenNODE_NO_WARNINGSis not defined).hexrcs commentedon Jan 16, 2020
Is this documented anywhere? I couldn't find anything about this env variable but it would certainly be great if we finally get this feature. :)
squallstar commentedon Jan 16, 2020
@hexrcs https://nodejs.org/api/cli.html#cli_node_no_warnings_1 (or search for
NODE_NO_WARNINGSon that page, the setting was added on Node 6).hexrcs commentedon Jan 16, 2020
Weird, because setting it to either a string
"1"or number1doesn't work on node v10 on my system (MacOS 10.14.6). (I was requiring thefs.promisesmodule.)Just tested on node v12.13.0 using the example below, also doesn't seem to work. :(
If the node interpreter is spawned with
node --no-warnings, thenprocess.emitWarningwill do nothing.squallstar commentedon Jan 16, 2020
@hexrcs I just tested on Node v12.13.0 and I am using Mac OS 10.15.2 (19C57), works great from here.
squallstar commentedon Jan 16, 2020
@hexrcs something which you can try is to spawn a child process after the env variable has been updated. I remember doing that on previous versions of node when using commander to create a node-based CLI tool.
hexrcs commentedon Jan 16, 2020
@squallstar Thanks for the tip :) I've been doing similar things:
#10802 (comment)
OK, I just upgraded node to v12.14.1, also doesn't work... Way too weird.
Anyway, I'll keep using the child process approach for now.
ErisDS commentedon Apr 20, 2020
I raised this same issue here (oops): #32876 and @sam-github kindly took the time to explain there's a solution using
process.removeAllListeners('warning').Updated to node 18.20. Removed warning messages from codify pkg using n…
made node runnable on linux
Migrate TestLanguage generation from Deno to Node.js (#128)