-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
How to prevent ExperimentalWarning on queueMicrotask feature detection in library code? #25592
Comments
There isn't anything you can do to prevent just a single occurrence of a warning. I would say that in this case the experimental warning is doing exactly what it should. People are able to experiment with |
Seems you don't understand that |
One option would be to not emit the warning until the function is actually called: diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js
index 40ad964f68..7f0f3be314 100644
--- a/lib/internal/bootstrap/node.js
+++ b/lib/internal/bootstrap/node.js
@@ -762,8 +762,6 @@ function setupGlobalEncoding() {
function setupQueueMicrotask() {
Object.defineProperty(global, 'queueMicrotask', {
get() {
- process.emitWarning('queueMicrotask() is experimental.',
- 'ExperimentalWarning');
const { queueMicrotask } =
NativeModule.require('internal/queue_microtask');
diff --git a/lib/internal/queue_microtask.js b/lib/internal/queue_microtask.js
index 6ca0c1e144..f8afda6d76 100644
--- a/lib/internal/queue_microtask.js
+++ b/lib/internal/queue_microtask.js
@@ -7,8 +7,15 @@ const {
enqueueMicrotask,
triggerFatalException
} = internalBinding('util');
+let emitExperimentalWarning = true;
function queueMicrotask(callback) {
+ if (emitExperimentalWarning) {
+ emitExperimentalWarning = false;
+ process.emitWarning('queueMicrotask() is experimental.',
+ 'ExperimentalWarning');
+ }
+
if (typeof callback !== 'function') {
throw new ERR_INVALID_ARG_TYPE('callback', 'function', callback);
}
|
As another option, since it's a getter, I can check that |
Well it will eventually be removed from experimental status and then you can ship your library with it. In the specific case of In the mean time, since your library is (from what I can tell) a polyfill library, why not just polyfill the feature? |
Sounds strange allow to polyfill something only when it's available stable in engines. It should work anywhere - even in IE6, even in Node 0.8, even in Node 11, but even when experimental status will be removed, it will cause a problem in Node 11.
See the comment above. Since now it's a getter, |
@zloirock since it seems you're not actually using queueMicrotask, you can check for |
@devsnek it's not so simple. It's also should be re-exported for a version without global namespace pollution and, theoretically, can be used internally in places where required microtask (for example, if someone wanna replace Node
|
core-js@3
containsqueueMicrotask
polyfill.queueMicrotask
added to Node.js 11 as an experimental feature.On getting
queueMicrotask
global property on Node.js 11, emitted anExperimentalWarning
. Without a special handler, this warning pollutes the global output.Even this method not used,
core-js
detect it by getting this property. So even import ofcore-js@3
pollutes the global output by this warning.core-js
is a quite popular library, so after updating to stabecore-js@3
, pollution of the global output will cause too many problems.Any ideas what should I do for preventing this problem?
process.on('warning', ..)
? But it does not look like a solution for a library.The text was updated successfully, but these errors were encountered: