-
Notifications
You must be signed in to change notification settings - Fork 29
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
require "stream/web" produces warning #114
Comments
I have the same warning with Node v16.8.0. The Web Streams API has been added in Node v16.5.0 but is experimental. I think you should use web-streams-polyfill until the API is stable (streams.cjs).
|
|
I want to use the stream version developers will probably use cuz they are not interchangeable.
I also use this pkg on other non-nodejs places like Deno - Deno don't have stuff like blob's backed up by the filesystem. so i would prefer not to use version detection. Deno for instances already have a global stream api... but i doubt this will be long lived, both Deno and Node's blob currently support async blobs and they have the potential to read data from the disc in a async manner, but non have a way of actually getting a blob from the disc yet. |
Could you, please, move var initialized;
try {
const { Blob } = require( "buffer" );
if ( Blob && !Blob.prototype.stream ) {
Blob.prototype.stream = function name ( params ) {
if ( !initialized && !globalThis.ReadableStream ) {
initialized = true;
try {
Object.assign( globalThis, require( "stream/web" ) );
}
catch ( error ) {
// TODO: Remove when only supporting node >= 16.5.0
Object.assign( globalThis, require( "web-streams-polyfill/dist/ponyfill.es2018.js" ) );
}
}
let position = 0;
const blob = this;
return new ReadableStream( {
"type": "bytes",
async pull ( ctrl ) {
const chunk = blob.slice( position, Math.min( blob.size, position + POOL_SIZE ) );
const buffer = await chunk.arrayBuffer();
position += buffer.byteLength;
ctrl.enqueue( new Uint8Array( buffer ) );
if ( position === blob.size ) {
ctrl.close();
}
},
} );
};
}
}
catch ( error ) {} |
It have been on my mind. we could do something like that. the stream are needed here also: Lines 154 to 164 in 0e07457
|
Yes, or export the function and call it in the |
(It is also possible to run NodeJS with the flag This project is still quite Browser & Deno friendly and dose not really depend on any built in NodeJS stuff and I would also like to keep it that way. So perhaps stream.cjs should expose a global function instead: |
Disable warnings is a bad practice, warnings are useful, but not in our case. |
Yea, I use Deno for some own hoppy stuff. not so much for work. |
I think the correct way is to export from /* c8 ignore start */
// 64 KiB (same size chrome slice theirs blob into Uint8array's)
const POOL_SIZE = 65536;
var ReadableStream;
module.exports = function getReadableStream () {
if ( !ReadableStream ) {
try {
ReadableStream = require( "stream/web" ).ReadableStream;
}
catch ( error ) {
// TODO: Remove when only supporting node >= 16.5.0
ReadableStream = require( "web-streams-polyfill/dist/ponyfill.es2018.js" ).ReadableStream;
}
try {
const { Blob } = require( "buffer" );
if ( Blob && !Blob.prototype.stream ) {
Blob.prototype.stream = function name ( params ) {
let position = 0;
const blob = this;
return new ReadableStream( {
"type": "bytes",
async pull ( ctrl ) {
const chunk = blob.slice( position, Math.min( blob.size, position + POOL_SIZE ) );
const buffer = await chunk.arrayBuffer();
position += buffer.byteLength;
ctrl.enqueue( new Uint8Array( buffer ) );
if ( position === blob.size ) {
ctrl.close();
}
},
} );
};
}
}
catch ( error ) {}
}
return ReadableStream;
}; And then use it where you need ReadableStream. |
What do you think? |
Hey, man, are you alive? Sorry for disturbing you, but let's close this issue and forget about it. |
Sry. I have been busy on other projects Uhm, okey. Why? |
I mean not just close, I can send PR with the fix, if you want. |
one smaller change could also be to do: const orig = process.emitWarning
process.emitWarning = () => {}
Object.assign(globalThis, require('node:stream/web'))
process.emitWarning = orig |
Yes, need to test. If this will work - it will be good.
…On 17.09.2021 20:35, Jimmy Wärting wrote:
one smaller change could also be to do:
const orig = process.emitWarning
process.emitWarning = () => {}
Object.assign(globalThis, require('node:stream/web'))
process.emitWarning = orig
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#114 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAH2MSGSXC4ACPTCMQ4Y55DUCN35VANCNFSM5DE25PZQ>.
|
This is a bad idea to publish I think, that Warning, that produced by this module requires attention, and must be removed. |
hi, will next version has a fix to this problem? |
with some degree i would be okey with that but i also need a prediction on what is best for the overall eco-system and guess what most ppl will use the most. I advocate that ppl will prefer the latest version of using the native streams by node also have some perf adv over a polyfill in a way that it's faster and can better be converted to from node/whatwg streams + that they are transferable via workers The problem with web-streams-polyfill and any (native or polyfilled) ReadableStream is that they are not interchangeable with each other, this have been reported a numbers of times, and i have had problem with it myself in
to summarize all the above problem with a code example you can't do this kind of things: import {WritableStream} from 'web-streams-polyfill'
new window.Blob().stream().pipeTo(new WritableStream({ ... })) // throws
new window.Blob().stream().pipeTo(new window.WritableStream({ ... })) // works okey this is going to throw an error: this will also be a problem if you use two different web-streams-polyfill versions import {ReadableStream} from '[email protected]'
import {WritableStream} from '[email protected]'
new ReadableStream().pipeTo(new WritableStream({})) this is going to throw the same kind of error: this is the hole underlying problem of why i do not want to bundle node-fetch into a 0 dependency cjs module. cuz we would then have one version and you would be using another. I would be comfortable with only using web-streams-polyfill if this got fixed |
Hi,
On node v16 it produces experimental warning.
Could you please use polyfill until
stream/web
feature will get stable status?Also instead of using
try/catch
for loadstream/web
you can checkprocess.version
and loadstream/web
if node version is >= 16.5.0.The text was updated successfully, but these errors were encountered: