So, I'm in the process of doing a long overdue update on a Node-based project, bundled with webpack and babel. In the process of updating webpack beyond v4, I've set up some of the polyfills I need by adding a resolve.fallback section to the config in my webpack.config.js:
resolve: {
extensions: [".ts", ".tsx", ".html", ".js"],
fallback: {
buffer: require.resolve("buffer"),
crypto: require.resolve("crypto-browserify"),
stream: require.resolve("stream-browserify"),
},
},
However, something (I suspect these polyfills, but I'm not sure) is now causing all instances of NodeJS Streams in my project to wind up being standard ReadableStreams, including the body of a response from an explicitly-imported node-fetch:
import {default as nodefetch} from 'node-fetch'
[...]
const response = await nodefetch(endpointURI, {
method: "POST",
headers: {
Authorization: authToken,
Origin: window.location.host,
},
body: JSON.stringify(data),
});
return response.body; // Attempting to call `response.body.pipe()` here
// will result in a "not a function" error. In a debugger,
// response.body appears to be a standard (Non-Node) ReadableStream.
So, not sure why this is happening but I'd love to find out! Relevant versions:
node: v16.15.1
node-fetch@2.6.7
webpack-cli@4.10.0
webpack@5.73.0
stream-browserify@3.0.0
@babel/core@7.18.6
@babel/preset-env@7.18.6
@babel/preset-react@7.18.6
@babel/preset-typescript@7.18.6
@babel/runtime@7.18.6