-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
TypeError: Data must be a string or a buffer #1659
Comments
@cstrangedk Off topic, you might want to use Material-UI v.1 which now provides a grid system instead of using |
Same issue here. I've found that when several components from
and if the
then this error occurs. Also what's really weird is that this happens in my project only when there are more than 3 such page components (importing X). For <= 3 it builds fine. EDIT: Looks like this is indeed a problem with style imports. When a component imports styles and is itself being imported (even indirectly) several times this error occurs. In the end I had to switch to JSS. |
Thanks @0xc0dec , I was able to workaround this issue and consolidate how my components import css modules. |
Crashes with an error during `gatsby build`, as documented on gatsbyjs/gatsby#1659
FYI @KyleAMathews and other @gatsbyjs maintainers, I’ve run into multiple problems relating to this issue as well, which I’ve documented in a test case repo here: https://github.com/digivizer/gatsby-1659 I’ve added notes to the README about how to reproduce the bug and differences in how it manifests between Gatsby 1.2 and 1.3+. In the test case repo, there are two separate branches with different
Interestingly, the component tree in the 1.3 branch builds successfully with the 1.2 These problems are not visible in It’s also not immediately obvious whether this is a problem in Gatsby itself, or whether it is something to do with the underlying libraries and tools. |
I'm also seeing this issue, and it looks to have something to do with importing css modules. It's strange because some css modules are importing fine. As an example I have a contact form which imports a button and it's relevant css file and it builds fine. I can create a new page and import that same button component and the build fails. If I don't import the css file on the newly created page, the build is successful. |
Looks like the issue is when generating the chunk, the chunk name is undefined. This causes crypto.js updateHash to fail because it expects a string or buffer. Now the question is why is the chunk name undefined |
This looks to be fixed in version 1.7.1 edit: Nevermind this still is an issue. I added another page and started getting the error again. |
Can confirm, 1.7.1 is still failing with the same error. |
The error is in |
From what I can see hashed-chunk-ids-plugin passes chunk.name to get-hash-fn. On some css modules chunk.name returns as undefined. If I omit typeof chunk.name !== undefined in the plugin it looks like latest css module is there but the previous was undefined. It look like a webpack issue, as hashed-chunk-plugins-id is expecting to get the chunk from webpack. I literally console.log the chunks to see what it was spitting out. also .cache/pages.json has the componentChunkName listed in the file |
I would be happy to add a PR with a regression test case for this, but am unsure how to fix it without a bit more help and guidance. |
We just need something to uniquely identify the chunk. On chunks without names, is there anything else that can be used to identify the chunks? |
Maybe the resource? But that might not be unique. I'm still looking through the chunks. Math.random() if chunk.name == undefined? |
It can't be random as it has to ID the chunk |
I don't see anything unique. The chunk.context shows the path to the file but that's not necessarily going to be unique. Do you know why the id returns null? |
So, I changed the plugin and the html build completes. Although I know the same css was already imported earlier in the page. I don't know if it fixes anything or just prevents the hashFn failure. I'm going to keep testing. var getHashFn = require("./get-hash-fn");
function HashedChunkIdsPlugin(options) {
this.options = options || {};
}
HashedChunkIdsPlugin.prototype.apply = function apply(compiler) {
var hashFn = getHashFn(this.options);
compiler.plugin("compilation", function (compilation) {
compilation.plugin("before-chunk-ids", function (chunks) {
chunks.forEach(function (chunk) {
if (chunk.id === null) {
if (typeof chunk.name !== "undefined") {
chunk.id = hashFn(chunk.name);
} else {
console.log(chunk);
}
}
});
});
});
};
module.exports = HashedChunkIdsPlugin; |
The HashedChunkIdsPlugin assumes that when For example, the issue documented here occurs when the following is passed through:
This may also indicate a problem with CSS Modules or Webpack (or an interaction between the two). Was able to get the site to build just now by using the path string provided in if (chunk.id === null) {
if (chunk.name !== undefined) {
chunk.id = hashFn(chunk.name);
} else {
chunk.id = hashFn(chunk.modules[0].rawRequest)
}
} |
rawRequest may not be unique, and I'm not sure that matters. So far, I have just been able to skip the chunks without names all together without issue. Right now, I'm assuming the reason the chunk doesn't have a name is because it was imported by a previous chunk. |
Thanks for looking at that. I’ll run a build skipping all chunks with undefined names and see if it behaves correctly and that all the CSS is present when it loads in the browser.
I don’t really know what Webpack’s standard is for error messages/internal exception handling, but at the very least, would be more robust to have a guard clause that checks that |
I think they may have fixed it in v 2.3 which is also what Gatsby is going to in v2 |
Yeah, so skipping the chunk as described above simply moves the error from compile time to run time, as documented here. Edit: This error happens in the same way, irrespective of whether the chunk is skipped, or whether the id gets filled in like |
I'm not getting that error. I tested on my environment throughout the night. I am currently running the following code so I can analyze which modules do not have chunk.id or chunk.name. I have nested components and multiple pages running. var getHashFn = require("./get-hash-fn");
function HashedChunkIdsPlugin(options) {
this.options = options || {};
}
HashedChunkIdsPlugin.prototype.apply = function apply(compiler) {
var hashFn = getHashFn(this.options);
compiler.plugin("compilation", function (compilation) {
compilation.plugin("before-chunk-ids", function (chunks) {
chunks.forEach(function (chunk) {
var c = {
path: chunk.modules[0].context,
id: chunk.id,
name: chunk.name
}
console.log(c);
if (chunk.id === null) {
if (typeof chunk.name !== "undefined") {
chunk.id = hashFn(chunk.name);
} else {
console.log(chunk.modules[0].context + ' was not run through the hash function');
}
}
});
});
});
};
module.exports = HashedChunkIdsPlugin; In my case. I am using Ant Design. It doesn't seem that it is failing on the actual css modules. The css modules are being extracted higher up in the webpack config. The HashedChunkIdsPlugin runs in the js build process. The reason it looked like it failed on css modules is because of the way Ant Design imports it's css modules. For example Button.js will import style.js and style.js will import style.css and button.css. It's actually style.js that returns chunk.id === null and chunk.name === undefined and fails the hash function. By this point the css is already extracted and Button is included in the parent page chunk, so skipping the style.js files works fine. I don't know why style.js is being separated to it's own chunk. |
Is this likely to be fixed in |
So after many hours of debugging this for my site (which seemed to break out of nowhere, I assume because of dependencies that got updated after re-running yarn), I decided to start fresh from the blog starter site. I slowly added my site's files into the newly created folder, building after each addition. Turns out my specific issue was the use of I'm not sure of the fix yet, but if that's not everyone else's issue, I'd recommend starting from scratch or something similar. I'll report back here when I find a solution to this. I'd still like to lazy load modules if possible. |
I have got the same issue, solved via third argument to require.ensure([], require => {
require('./something');
}, 'name-of-my-chunk')
However, of course it would be nice to make this working without this additional friction. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@Stale the issue is still actual. |
Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help! |
I produce the following error after a
gatsby build
:My package.json is:
The text was updated successfully, but these errors were encountered: