Closed RahmiTufanoglu closed 4 years ago
And here is the gatsby-browser.js content. Layout is an appbar which gets icon an title from contentful.
import React from "react";
import Layout from "./src/components/layout";
export const wrapPageElement = ({ element, props }) => {
return <Layout {...props}>{element}</Layout>;
};
export const onServiceWorkerUpdateReady = () => {
const answer = window.confirm(
"This application has been updated. " +
"Reload to display the latest version?"
);
if (answer === true) {
window.location.reload();
}
};
export const registerServiceWorker = () => true;
@RahmiTufanoglu Do you have a reproduction?
@oliviertassinari The project is closed-source. This is my first time. Could you tell me how I can bring you the reproduction?
The idea is to create a new & minimal repository that demonstrates the issue.
I try to create a minimal repository.
@oliviertassinari I can invite you to the test repo on gitlab
@RahmiTufanoglu No thanks, we need a minimal & public reproduction.
@oliviertassinari Hope it helps. You can ignore the Pipeline because of Netlify.
Gitlab: https://gitlab.com/rahmi_tufanoglu/homepage-test Netlify: https://5ea2bb60495f007a6b13ae80--dreamy-goldstine-39731a.netlify.app/
@RahmiTufanoglu Sorry, please remove as much code as possible, it should contain the strict minimum to reproduce the issue.
@oliviertassinari Ok. Removed code. Is this enough? And updated the netlify link.
I get the same error with 2.1.7.
The problem only occurrs with Node 14. fs.writeFileSync
never accepted null
as data
argument, but before node 14 it used to coerce it to a supported data type, now it doesn't.
See History
section here: https://nodejs.org/dist/latest-v14.x/docs/api/fs.html#fs_fs_writefile_file_data_options_callback
onPreBootstrap
method is not exactly a copy-paste from typography plugin, which sets module
to string by default:
when material-ui plugin sets it to null
:
Possible Solution: set module
to a dummy module string, like typography plugin does.
Does it work better with https://github.com/hupe1980/gatsby-plugin-material-ui/releases/tag/v2.1.7, it's now using the cache API of Gatsby?
Nope, the problem is not with the api, but with passing null
to fs.writeFileSync
This is the gist of the error:
ERROR #11321 PLUGIN
"gatsby-plugin-material-ui" threw an error while running the onPreBootstrap lifecycle:
The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received null
40 | }
41 |
> 42 | fs.writeFileSync(path.join(dir, "styles-provider-props.js"), module);
| ^
43 | }; // Copy and past from https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-typography
44 |
45 |
File: node_modules/gatsby-plugin-material-ui/gatsby-node.js:42:6
Error: TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received null
- gatsby-node.js:42 Object.exports.onPreBootstrap
[project]/[gatsby-plugin-material-ui]/gatsby-node.js:42:6
@le0nik Ok, so the solution would be not to write anything to the file system if module
is empty?
@oliviertassinari No, this would cause errors here https://github.com/hupe1980/gatsby-plugin-material-ui/blob/05588ae56ea3e9a7b2f5e4f1d2ad7234ba971d89/gatsby-plugin-material-ui/src/gatsby-ssr.js#L5 and here https://github.com/hupe1980/gatsby-plugin-material-ui/blob/05588ae56ea3e9a7b2f5e4f1d2ad7234ba971d89/gatsby-plugin-material-ui/src/gatsby-browser.js#L4 where this file is imported. The simplest solution is to set module to module.exports = null
in else block in onPreBootstrap
.
EDIT: Here's a PR that fixes it https://github.com/hupe1980/gatsby-plugin-material-ui/pull/49/files
I'm getting the error log from gitlab ci (the output below) when deploying the website with the gatsby-plugin-material-ui to aws s3. The deployment without the plugin works. My app works locally, but on command "gatsby serve" the plugin does not render all components correctly. Only after a refresh I get the correct page. I'm using the latest versions of every npm package.
Gitlab CI Error:
error "gatsby-plugin-material-ui" threw an error while running the onPreBootstrap lifecycle:
Gitlab CI:
gatsby-config.js:
package.json: