Open nclzz opened 10 months ago
Is there any workaround?
Same error here.
I was able to work around this with the following webpack config, added to gatsby-node.ts
(TypeScript Gatsby project):
import { CreateWebpackConfigArgs } from 'gatsby';
import webpack from 'webpack';
export const onCreateWebpackConfig = ({ actions, plugins, ...args }: CreateWebpackConfigArgs) => {
const buildWebpackConfig =
args.stage === 'build-html'
? {
resolve: {
// Handle Uncaught TypeError: util.inherits is not a function - https://github.com/webpack/webpack/issues/1019
mainFields: ['browser', 'module', 'main'],
// Handle unsupported node scheme - https://github.com/webpack/webpack/issues/13290#issuecomment-987880453
fallback: {
util: require.resolve('util'),
stream: require.resolve('stream-browserify'),
},
},
}
: {};
actions.setWebpackConfig({
plugins: [
// Handle unsupported node scheme - https://github.com/webpack/webpack/issues/13290#issuecomment-987880453
new webpack.NormalModuleReplacementPlugin(/^node:/, (resource) => {
resource.request = resource.request.replace(/^node:/, '');
}),
],
...buildWebpackConfig,
});
};
What this does is configures mainFields (not entirely sure how this works yet) and fallback polyfills for building only, and adds the webpack.NormalModuleReplacementPlugin
plugin to remove the use of any node:
URI schemes. I cobbled this solution together after reading through multiple threads, and at least the project deploys now.
For this to work, I needed to install util
and stream-browserify
packages, like so:
npm i --save-dev util && npm i --save stream-browserify
After those configurations, I was finally able to build the project.
Hope that gets anyone else with this issue on the right path!
The error I resolved with this workaround was:
Reading from "node:events" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
error Generating SSR bundle failed
Reading from "node:stream" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
error Generating SSR bundle failed
Reading from "node:util" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
not finished Building HTML renderer - 5.564s
The first thing I tried was adding the NormalModuleReplacementPlugin
webpack plugin in gatsby-node
in order to replace node:
URIs. Start there if you're just stumbling on this thread with similar issues.
import webpack from 'webpack';
export const onCreateWebpackConfig = ({ actions, plugins }) => {
actions.setWebpackConfig({
plugins: [
// Handle unsupported node scheme - https://github.com/webpack/webpack/issues/13290#issuecomment-987880453
new webpack.NormalModuleReplacementPlugin(/^node:/, (resource) => {
resource.request = resource.request.replace(/^node:/, '');
}),
],
});
};
If you still get errors, look at my previous response for additional workarounds I needed to use. Hope this helps.
EDIT: module: { rules: [{ test: /form-data/, use: loaders.null() }], },
helped me for a successful build
@jmmrte thank you for the workaround. But somehow it leads to a new error on my project listing:
failed Building static HTML for pages - 1.753s
ERROR #95312 HTML.COMPILATION
"window" is not available during server-side rendering. Enable "DEV_SSR" to debug this during "gatsby develop".
See our docs page for more info on this error: https://gatsby.dev/debug-html
1 | / eslint-env browser /
2 | module.exports = typeof self == 'object' ? self.FormData : window.FormData; | ^ 3 |
WebpackError: ReferenceError: window is not defined
browser.js:2 [transfer-unit]/[form-data]/lib/browser.js:2:1
bootstrap:19 transfer-unit/webpack/bootstrap:19:1
index.js:129 [transfer-unit]/[get-intrinsic]/index.js:129:15
bootstrap:19 transfer-unit/webpack/bootstrap:19:1
js.cookie.js:114 [transfer-unit]/[js-cookie]/src/js.cookie.js:114:1
bootstrap:19 transfer-unit/webpack/bootstrap:19:1
static-entry.js:224 transfer-unit/.cache/static-entry.js:224:27
browser.js:219 [transfer-unit]/[debug]/src/browser.js:219:1
Do you have a guess as to why this might be? I access window object as mentioned from the Gatsby docs by checking it before always. It has worked before.
@mafiusu ... window is not available During the build process , i also had the same issue i did this and it worked ... module.exports = typeof window !== 'undefined' && self === 'object' ? self.FormData : window.FormData;
]
this worked For me if you
npm install stream-browserify emitter
on gatsby-node.js file: add
`
const webpack = require('webpack'); const stream = require('stream'); const Emitter = require('emitter');
exports.onCreateWebpackConfig = ({ actions }) => { actions.setWebpackConfig({ plugins: [ new webpack.NormalModuleReplacementPlugin(/^node:/, (resource) => { resource.request = resource.request.replace(/^node:/, ''); }), ], resolve: { fallback: { "stream": require.resolve("stream-browserify"), // Use stream-browserify as a polyfill "emitter": require.resolve("emitter"), }, }, }); };
if you are using webpack.config.js file, update it with the following:
const path = require("path");
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
fallback: {
"stream": require.resolve("stream-browserify"),
},
},
});
};
Above solutions don't work for me. void[0] is not a function,
etc. Have been stuck for a while now. Any updates?
Hi,
I have fixed this with #38516, which was published as gatsby@5.13.2. Hope this helps!
Preliminary Checks
Description
Hello, I have a Gatsby project that when I import the library @datocms/cma-client-browser, it gives the following error during the build phase (gatsby build). The original project is complex, but I was able to reproduce the error in the linked repo.
The error occurs both locally and on Netlify. By removing import { buildClient } from "@datocms/cma-client-browser"; from the index.js file, the build completes successfully. Would you be able to help me understand the issue? Unfortunately, the error doesn't provide much information. It might be related to Gatsby's webpack settings, but all the workarounds I've tried haven't solved the issue.
Reproduction Link
https://github.com/MultiDigital/datocms-ssr
Steps to Reproduce
Expected Result
Build completed succesfully
Actual Result
ERROR #98123 WEBPACK
Generating SSR bundle failed
Reading from "node:events" is not handled by plugins (Unhandled scheme). Webpack supports "data:" and "file:" URIs by default. You may need an additional plugin to handle "node:" URIs.
File: node:events
ERROR #98123 WEBPACK
Generating SSR bundle failed
Reading from "node:stream" is not handled by plugins (Unhandled scheme). Webpack supports "data:" and "file:" URIs by default. You may need an additional plugin to handle "node:" URIs.
File: node:stream
ERROR #98123 WEBPACK
Generating SSR bundle failed
Reading from "node:util" is not handled by plugins (Unhandled scheme). Webpack supports "data:" and "file:" URIs by default. You may need an additional plugin to handle "node:" URIs.
File: node:util
Environment
Config Flags
No response