-
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
Develop works, build fails: Cannot read property 'initial' of undefined #1846
Comments
Fix: Add |
I could reproduce the same problem. It is somehow related to the number of pages that you have. I have created a file
Also, I would like to mention, that there is an issue webpack-contrib/extract-text-webpack-plugin#115 which says that CommonsChunkPlugin somehow screws up the build under some conditions. |
@rshah03 could you please re-open the issue? The solution of editing files in |
@just-boris Thanks! Re-opened the issue. Yeah, I was trying to find other possible solutions, but wasn't able to. Thought I would stick with that temp fix for the time being. I will take a look at your sample project and likely redo my project with fewer pages/components. |
My workaround, fwiw, in my { ...
"scripts": {
"patch": "sed -i -e 's/if(c\\.initial) return;/if(!c||c.initial) return;/g' ./node_modules/extract-text-webpack-plugin/index.js",
"build": "npm run patch && gatsby build",
}
...
} |
This seems to be caused by Webpack's RemoveEmptyChunksPlugin and how Webpack removes chunks. Before applying ExtractTextWebpackPlugin, Webpack runs RemoveEmptyChunksPlugin which can remove component chunks from Webpack's chunk list. The problem is that it doesn't remove the empty chunk from the chunk called I am not sure where I should report this, and what is the best workaround at the moment. |
Have you checked the following link: webpack-contrib/extract-text-webpack-plugin#170 Applying @azoff workaround gives the following error:
Related to #1850 It seems the version of webpack and extract-text-webpack-plugin is too old in gatsby. |
I guess this bug will have to wait for Gatsby 2 (#1824), since I don't think Webpack devs will be interested in bug reports for Webpack 1. I am pretty sure that the bug still exists in Webpack 3, but I currently don't have the time to create a minimal example. Maybe someone else could take a Webpack 3 config and try to replicate as follows:
I worked around this bug by eliminating inter-page imports. I had a lot of pages import stuff from an index page and that was causing the index page to become an empty chunk (my guess is that it was being inlined into other chunks). |
@nickguletskii What was the process you followed? With this procedure you avoid the workaround of @azoff and also the error #1850? |
upgrade to latest version |
I have upgraded to latest version and I continue with same issue |
Works fine when I don't have gatsby develop running. |
hitting the same issue here but with ~100 markdown files and 5 templates... any idea how to solve this ? |
Yes @revolunet you should not have pages or components that are called within other pages within the folder of pages, that is, inside the folder of pages you must only have the pages that are functional for gatsby, if any of those pages needs some components you must position them outside of the page folder, this resolve the issue for me |
in my case i have nothing in |
after a fun hunt, i found a hacky workaround, but i cant understand why it solves the issue In so as @canoqb10 mentions, one shouldn't put reusable components inside |
Stumbled upon the same error, triggered from that buggy code : const onRef = {
log404();
};
return (
<Page
ref={onRef} the const onRef = () => {
log404();
}; BTW, this trigger via webpack the infamous "Cannot read property 'initial' of undefined". The issue source is the user code itself, but the error come from https://github.com/webpack-contrib/extract-text-webpack-plugin, just submitted a PR for webpack 1 users |
@rshah03 In fact your answer from August it the only right answer, if you do the same alt line 23 also |
Bump, stumbling on this also. Tried the patch from #1846 (comment), but got the error from #1846 (comment) |
@neilyoung Though that works, it's generally bad practice to modify files within the node_modules directory, so it's not an ideal fix. I guess it would be okay for development, but probably not a good idea for production. @Zephir77167 I ended up creating a new iteration of my project without nesting components within each other. This worked fine and the issue didn't come up again. I think Gatsby can handle 1 layer of directly embedded components, but no more. |
Yeah I guess so, I moved all the components in |
To me, this issue occurred when I imported constant in one page from another page. |
Did anyone find the fix of this issue?? |
…standard component. See: gatsbyjs/gatsby#1846
* initial speakers and workshops commit * fix build error by moving out shared page component from template to standard component. See: gatsbyjs/gatsby#1846 * use lodash to split speaker list into chunks of two speakers for column formatting * break out NavigationLink into separate component * Added fa bullets to content, shaded background
If that can help anyone out there, I encountered this error because a component under @KyleAMathews Could this be in the docs, in shiny flashing bold? |
v2 is out which upgrades webpack and plugins + removes the confusing layouts component so closing. See the v2 migration guide to upgrade! https://next.gatsbyjs.org/docs/migrating-from-v1-to-v2/ |
I hit this issue too - I added the workaround to |
* chore(pf4-docs): show components as secondary items and package * remove pascal-case * try gatsby/webpack patch from gatsbyjs/gatsby#1846 (comment) * fix error reserved keyword switch * remove patch * patch again * try out different travis build env * travis linux build * reset travis config
My
develop
version runs fine, with no issues. However, I get the following error(s) when I rungatsby build
or any sort of production script:I have absolutely no idea what the root of this problem is. Any help would be appreciated.
The text was updated successfully, but these errors were encountered: