Description
Currently, there's a warning output by node about fs.promises being experimental. It's a warning in Node v10 that disappears in v12.
You don't have to use fs.promises to get this warning, it happens if one of your dependencies or sub-dependencies require it. In the case of bin scripts, the warning is shown to users of my script - this is what I mean by "bubbling up".
In my case, my code doesn't use this API, therefore the warning is not useful to me. Also in my case, the Node.js code that is outputting this warning is a bin script - specifically a CLI tool that performs validation. In this context the warning is not just useless, but actively problematic as it appears to form part of the validation output from the tool.
- Version: 10.16.0
- Platform: Mac and various Linuxes
What steps will reproduce the bug?
I have created a minimal reproduction case here: https://github.com/ErisDS/node-warn-demo
To reproduce:
npm install -g node-warn-demo@v1
nvm use 10
(assuming you have nvm or similar to switch node versions)warn
You'll see the following output:
Hello World
(node:53729) ExperimentalWarning: The fs.promises API is experimental
There are a few different subtle problems here:
- I'm not even using the required dependency, the simple act of requiring it causes the warning
- The warning is of no use to users of my script, but I can't control it.
- The warning outputs after "Hello World" i.e. it's unpredictable when it will output, meaning in a CLI context with lots of output, it will appear in the middle of your output.
How often does it reproduce? Is there a required condition?
This is always reproducible on Node v10.
What is the expected behavior?
I personally don't think it makes sense for the warning to bubble up from the dependency, certainly not on require.
Although I can see an argument that it's maybe useful knowledge for me as a user of the dependency, surely that should be up to the maintainer of the dependency whether or not they think their users need to know?
As the maintainer of the CLI tool, I definitely want control to prevent the warning bubbling up further as I know that it is of no use to my target audience, and is in fact going to be confusing for them.
What do you see instead?
There is no way to disable the warning.
We've tried adding the following to the top of the bin script:
#!/usr/bin/env node --no-warnings
- this works on mac and some linuxes but breaks on others as reported here#!/usr/bin/env -S node --no-warnings
- this works on mac and and some linuxes but breaks on ubuntu as reported here
I've seen other ideas about environment variables and so on, but every method I've tested either doesn't work at all, is not platform agnostic, or does not apply to the bin script context.
Additional information
You can see the real world example where we have this problem here on the gscan repo along with issues where we've had churn trying to fix it here and here.