Gatsby: useStaticQuery causing failed builds

Created on 27 May 2020  ·  6Comments  ·  Source: gatsbyjs/gatsby

Description

Failed builds, specifically useStaticQuery is causing a failed json file import error. gatsby develop works just fine though.

Steps to reproduce

Build a project with useStaticQuery with the latest Gatsby.

Expected result

Build should succeed.

Actual result

Note: All failed modules are using useStaticQuery

success open and validate gatsby-configs - 0.053s
success load plugins - 1.963s
success onPreInit - 0.015s
success delete html and css files from previous builds - 0.012s
success initialize cache - 0.007s
success copy gatsby files - 0.075s
success onPreBootstrap - 0.012s
success createSchemaCustomization - 0.005s
success source and transform nodes - 13.019s
success building schema - 0.665s
success createPages - 0.035s
success createPagesStatefully - 0.067s
success onPreExtractQueries - 0.002s
success update schema - 0.042s
success extract queries from components - 0.755s
success write out requires - 0.005s
success write out redirect data - 0.002s
success Build manifest and related icons - 0.104s
success onPostBootstrap - 0.110s
⠀
info bootstrap finished - 21.569s
⠀
failed Building production JavaScript and CSS bundles - 14.010s

 ERROR #98124  WEBPACK

Generating JavaScript bundles failed

Can't resolve '../../public/static/d/1256177919.json' in '/Users/tyler/jolt/toddrantula-dashboard/src/components'

If you're trying to use a package make sure that '../../public/static/d/1256177919.json' is installed. If you're trying to use a local file make sure that the path is correct.

File: src/components/BigEightDashboardv2.js


 ERROR #98124  WEBPACK

Generating JavaScript bundles failed

Can't resolve '../../public/static/d/3943076234.json' in '/Users/tyler/jolt/toddrantula-dashboard/src/components'

If you're trying to use a package make sure that '../../public/static/d/3943076234.json' is installed. If you're trying to use a local file make sure that the path is correct.

File: src/components/departmentList.js


 ERROR #98124  WEBPACK

Generating JavaScript bundles failed

Can't resolve '../../public/static/d/46188684.json' in '/Users/tyler/jolt/toddrantula-dashboard/src/components'

If you're trying to use a package make sure that '../../public/static/d/46188684.json' is installed. If you're trying to use a local file make sure that the path is correct.

File: src/components/saasMetrics.js


 ERROR #98124  WEBPACK

Generating JavaScript bundles failed

Can't resolve '../../public/static/d/856328897.json' in '/Users/tyler/jolt/toddrantula-dashboard/src/components'

If you're trying to use a package make sure that '../../public/static/d/856328897.json' is installed. If you're trying to use a local file make sure that the path is correct.

File: src/components/layout.js

not finished run queries - 14.071s

Environment

  System:
    OS: macOS 10.15.4
    CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.16.1 - ~/.nvm/versions/node/v12.16.1/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.13.4 - ~/.nvm/versions/node/v12.16.1/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 83.0.4103.61
    Firefox: 75.0
    Safari: 13.1
  npmPackages:
    gatsby: ^2.20.12 => 2.22.11
    gatsby-cli: ^2.12.36 => 2.12.36
    gatsby-image: ^2.2.39 => 2.4.5
    gatsby-plugin-anchor-links: ^1.1.1 => 1.1.1
    gatsby-plugin-manifest: ^2.3.3 => 2.4.9
    gatsby-plugin-material-ui: ^2.1.8 => 2.1.8
    gatsby-plugin-offline: ^3.0.32 => 3.2.7
    gatsby-plugin-react-helmet: ^3.1.21 => 3.3.2
    gatsby-plugin-sharp: ^2.5.3 => 2.6.9
    gatsby-source-filesystem: ^2.2.2 => 2.3.8
    gatsby-source-google-spreadsheet: ^2.0.0 => 2.0.0
    gatsby-transformer-csv: ^2.2.1 => 2.3.2
    gatsby-transformer-sharp: ^2.4.3 => 2.5.3
  npmGlobalPackages:
    gatsby: 2.22.11

Most helpful comment

+1

I don't use onPostBuild scripts, either, but I'm getting the same WEBPACK error on components with useStaticQuery

failed Building production JavaScript and CSS bundles - 20.810s

 ERROR #98124  WEBPACK

Generating JavaScript bundles failed

Can't resolve '../../../../public/static/d/1318958187.json' ....

All 6 comments

I just realized that I have a post-build hook that moves the files. If I remove it, the errors are gone. It seems that gatsby is still compiling HTML when the post build runs..I.E. it is not done yet.

exports.onPostBuild = () => {
 fs.renameSync('./public', './server/public')
}

Thank you for opening this!

The results of static queries are put into those JSON files you see missing so your move of the files will definitely be the cause. I think it's safer to move your files in a postbuild npm script than in the lifecycle. More information would also be here: https://github.com/gatsbyjs/gatsby/issues/1878

We're marking this issue as answered and closing it for now but please feel free to comment here if you would like to continue this discussion. We also recommend heading over to our communities if you have questions that are not bug reports or feature requests. We hope we managed to help and thank you for using Gatsby!

I'm having the same issue and I don't have any onPostBuild scripts

+1

I don't use onPostBuild scripts, either, but I'm getting the same WEBPACK error on components with useStaticQuery

failed Building production JavaScript and CSS bundles - 20.810s

 ERROR #98124  WEBPACK

Generating JavaScript bundles failed

Can't resolve '../../../../public/static/d/1318958187.json' ....

I am also getting this issue.

Hi, i'm also running into the same issue, any updates ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andykais picture andykais  ·  3Comments

benstr picture benstr  ·  3Comments

jimfilippou picture jimfilippou  ·  3Comments

brandonmp picture brandonmp  ·  3Comments

KyleAMathews picture KyleAMathews  ·  3Comments