Error if using cache
tadeas22 opened this issue · 2 comments
tadeas22 commented
Hello
i am getting into a issue when running gatsby build
: Cannot read property 'childImageSharp' of null
success run queries - ...
failed Building static HTML for pages - ...s
ERROR #95313
Building static HTML failed for path "/..."
See our docs page for more info on this error: https://gatsby.dev/debug-html
WebpackError: TypeError: Cannot read property 'childImageSharp' of null
- build-html.js:110 doBuildPages
[pages]/[gatsby]/dist/commands/build-html.js:110:24
- build-html.js:124 async buildHTML
[pages]/[gatsby]/dist/commands/build-html.js:124:3
- build.js:200 async build
[pages]/[gatsby]/dist/commands/build.js:200:5
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! synetech-web@2.0.0 build: `gatsby build --prefix-paths`
Steps to reproduce:
- Create gatsby page with markdowns with paths to file in frontmatter
- First build without cache to create the cache
- Modify the source markdown in any way. For example add empty line. The modification must trigger
onCreateNode
- Second build with cache from step 2.
As the result WebpackError: TypeError: Cannot read property 'childImageSharp' of null
is thrown.
After deep dive into function fmImagesToRelative
i realize that array fileNodes
did not contain any node (except one), because onCreateNode
was call exactly ones for modified markdown.
gatsby-remark-relative-images/src/index.js
Line 113 in 6e2a795
As work around y must register all nodes before first call of fmImagesToRelative
let isRegister = true
exports.onCreateNode = ({ node, getNodes }) => {
if(isRegister) {
const nodes = getNodes()
nodes.forEach(node => fmImagesToRelative(node))
isRegister = false
}
fmImagesToRelative(node); // convert image paths for gatsby images
// ...
};
danielmahon commented
had no idea getNodes()
existed... pushing update soon that should fix this
tadeas22 commented
Cool nice work thx