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

Cannot disable warnings when node is launched via a shell script. #10802

Closed
politician opened this issue Jan 14, 2017 · 12 comments

Comments

@politician
Copy link

commented Jan 14, 2017

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.

@politician politician changed the title Cannot disable warnings when scripts are launched from the shell. Cannot disable warnings when node is launched via a shell script. Jan 14, 2017

cjihrig added a commit to cjihrig/node-1 that referenced this issue Jan 19, 2017
process: add NODE_NO_WARNINGS environment variable
This commit adds support for a NODE_NO_WARNINGS environment
variable, which duplicates the functionality of the --no-warnings
command line flag.

Fixes: nodejs#10802
PR-URL: nodejs#10842
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
italoacasas added a commit to italoacasas/node that referenced this issue Jan 25, 2017
process: add NODE_NO_WARNINGS environment variable
This commit adds support for a NODE_NO_WARNINGS environment
variable, which duplicates the functionality of the --no-warnings
command line flag.

Fixes: nodejs#10802
PR-URL: nodejs#10842
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
italoacasas added a commit to italoacasas/node that referenced this issue Jan 27, 2017
process: add NODE_NO_WARNINGS environment variable
This commit adds support for a NODE_NO_WARNINGS environment
variable, which duplicates the functionality of the --no-warnings
command line flag.

Fixes: nodejs#10802
PR-URL: nodejs#10842
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
MylesBorins added a commit that referenced this issue May 16, 2017
process: add NODE_NO_WARNINGS environment variable
This commit adds support for a NODE_NO_WARNINGS environment
variable, which duplicates the functionality of the --no-warnings
command line flag.

Fixes: #10802
PR-URL: #10842
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
MylesBorins added a commit that referenced this issue May 18, 2017
process: add NODE_NO_WARNINGS environment variable
This commit adds support for a NODE_NO_WARNINGS environment
variable, which duplicates the functionality of the --no-warnings
command line flag.

Fixes: #10802
PR-URL: #10842
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
andrew749 added a commit to michielbaird/node that referenced this issue Jul 19, 2017
process: add NODE_NO_WARNINGS environment variable
This commit adds support for a NODE_NO_WARNINGS environment
variable, which duplicates the functionality of the --no-warnings
command line flag.

Fixes: nodejs/node#10802
PR-URL: nodejs/node#10842
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
@mnpenner

This comment has been minimized.

Copy link

commented Feb 5, 2019

What's the solution?

When I try putting this at the top of my file:

#!/usr/bin/env NODE_NO_WARNINGS=1 node

I just get:

/usr/bin/env: ‘/path/to/my/script’: Text file busy
@Doragd

This comment has been minimized.

Copy link

commented Mar 14, 2019

@mnpenner
like this:

#!/usr/bin/env
export NODE_NO_WARNINGS=1

it works. :)

@mnpenner

This comment has been minimized.

Copy link

commented Mar 14, 2019

@Doragd Huh? How would that work... the file contains JavaScript, it'll syntax error on export NODE_NO_WARNINGS=1

@hexrcs

This comment has been minimized.

Copy link

commented Apr 20, 2019

@mnpenner According to the link from @bnoordhuis, looks like it depends on the OS.

Does anyone have a cross-platform way to set the environment variable? Still haven't found any after researching and experimenting for a while. :(

@bnoordhuis

This comment has been minimized.

Copy link
Member

commented Apr 21, 2019

@hexrcs env -S - it's not standard but it works with BSD and GNU env(1).

@Doragd

This comment has been minimized.

Copy link

commented May 8, 2019

@mnpenner
20190508130041.png
It really works for a shell script.

@mnpenner

This comment has been minimized.

Copy link

commented May 8, 2019

@Doragd We're talking about an executable .js file, not a .sh file which subsequently runs node.

@hexrcs

This comment has been minimized.

Copy link

commented May 12, 2019

I am now using a launcher script to spawn a child_process to work around this limitation. Ugly, but fine for my purpose - it works with npm link, global installs and whatnot.

#!/usr/bin/env node
const { spawnSync } = require("child_process");
const { resolve } = require("path");

// Say our original entrance script is `app.js`
const cmd = "node --no-warnings " + resolve(__dirname, "app.js");
spawnSync(cmd, { stdio: "inherit", shell: true });

If you only wanted to disable the warnings because you used the fs.promises API as I did, I would recommend next time wrapping the original APIs in a promise manually, or sticking to util.promisify, sync version of the APIs, instead of using this workaround.

@dvdbot

This comment has been minimized.

Copy link

commented May 13, 2019

Why is this closed? We really need a better way to disable warnings or at least to disable the Experimental API warning

@tdd

This comment has been minimized.

Copy link
Member

commented May 24, 2019

You can just change your shebang to #! /usr/bin/env node --no-warnings

@jasnell

This comment has been minimized.

Copy link
Member

commented May 24, 2019

The --no-warnings flag can be used with the NODE_OPTIONS environment variable.

$ NODE_OPTIONS=--no-warnings ./node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.