gatsby: Develop works, build fails: Cannot read property 'initial' of undefined
My develop
version runs fine, with no issues. However, I get the following error(s) when I run gatsby build
or any sort of production script:
/home/coder/Developer/portfolio/node_modules/extract-text-webpack-plugin/index.js:22
if(c.initial) return;
^
TypeError: Cannot read property 'initial' of undefined
at ExtractTextPlugin.<anonymous> (/home/coder/Developer/portfolio/node_modules/extract-text-webpack-plugin/index.js:22:8)
at Array.forEach (native)
at ExtractTextPlugin.mergeNonInitialChunks (/home/coder/Developer/portfolio/node_modules/extract-text-webpack-plugin/index.js:21:16)
at ExtractTextPlugin.<anonymous> (/home/coder/Developer/portfolio/node_modules/extract-text-webpack-plugin/index.js:275:12)
at Array.forEach (native)
at ExtractTextPlugin.<anonymous> (/home/coder/Developer/portfolio/node_modules/extract-text-webpack-plugin/index.js:273:21)
at /home/coder/Developer/portfolio/node_modules/extract-text-webpack-plugin/node_modules/async/lib/async.js:52:16
at Object.async.forEachOf.async.eachOf (/home/coder/Developer/portfolio/node_modules/extract-text-webpack-plugin/node_modules/async/lib/async.js:236:30)
at Object.async.forEach.async.each (/home/coder/Developer/portfolio/node_modules/extract-text-webpack-plugin/node_modules/async/lib/async.js:209:22)
at ExtractTextPlugin.<anonymous> (/home/coder/Developer/portfolio/node_modules/extract-text-webpack-plugin/index.js:237:10)
at Compilation.applyPluginsAsync (/home/coder/Developer/portfolio/node_modules/tapable/lib/Tapable.js:71:13)
at Compilation.seal (/home/coder/Developer/portfolio/node_modules/webpack/lib/Compilation.js:525:7)
at Compiler.<anonymous> (/home/coder/Developer/portfolio/node_modules/webpack/lib/Compiler.js:397:15)
at /home/coder/Developer/portfolio/node_modules/tapable/lib/Tapable.js:103:11
at Compilation.<anonymous> (/home/coder/Developer/portfolio/node_modules/webpack/lib/Compilation.js:445:10)
at /home/coder/Developer/portfolio/node_modules/webpack/lib/Compilation.js:417:12
I have absolutely no idea what the root of this problem is. Any help would be appreciated.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 9
- Comments: 28 (9 by maintainers)
Commits related to this issue
- fix build error by moving out shared page component from template to standard component. See: https://github.com/gatsbyjs/gatsby/issues/1846 — committed to productmindset/site by derektiffany 6 years ago
- initial speakers commit (#70) * initial speakers and workshops commit * fix build error by moving out shared page component from template to standard component. See: https://github.com/gatsbyjs... — committed to productmindset/site by product-mindset 6 years ago
- fix bug (gatsby issue 1846) https://github.com/gatsbyjs/gatsby/issues/1846 — committed to nextstrain/static by jameshadfield 6 years ago
- adding patch cmd from: gatsbyjs/gatsby/issues/1846#issuecomment-324744367 — committed to justsml/dans-blog by justsml 6 years ago
- try gatsby/webpack patch from https://github.com/gatsbyjs/gatsby/issues/1846#issuecomment-324744367 — committed to jschuler/patternfly-react by jschuler 6 years ago
- chore(pf4-docs): show components as secondary items and package (#928) * chore(pf4-docs): show components as secondary items and package * remove pascal-case * try gatsby/webpack patch from htt... — committed to patternfly/patternfly-react by jschuler 6 years ago
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
@rshah03 could you please re-open the issue? The solution of editing files in
node_modules
is not acceptable, because people usually do not modify third-party-dependencies directly.Fix: Add
if (typeof c === 'undefined') return;
right below line 21 innode_modules/extract-text-webpack-plugin/index.js
To me, this issue occurred when I imported constant in one page from another page. Fixed by moving constant to utilities folder and importing from there.
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/
My workaround, fwiw, in my
package.json
file: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:
shared
, tell Webpack to make a chunk for it (or however that works, I am not sure).shared
and have Webpack make chunks for them.shared
chunk is being deleted byRemoveEmptyChunksPlugin
.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).
I hit this issue too - I added the workaround to
node_modules/gatsby-1-config-extract-plugin/node_modules/extract-text-webpack-plugin
, and then when I re-rangatsby build
the actual error showed up. There was a syntax error in my page template - I was assigning to a const. Just a heads up - for me this error was masking the syntax error, so when I fixed the syntax error I could remove the workaround and the build succeeded.Did anyone find the fix of this issue?? Other than modifying the node modules files .
Bump, stumbling on this also. Tried the patch from https://github.com/gatsbyjs/gatsby/issues/1846#issuecomment-324744367, but got the error from https://github.com/gatsbyjs/gatsby/issues/1846#issuecomment-326858100