Skip to content
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

Built site fails when deployed to Amazon S3 in 2.9.0 and later #15151

Closed
gjhltn opened this issue Jun 26, 2019 · 20 comments
Closed

Built site fails when deployed to Amazon S3 in 2.9.0 and later #15151

gjhltn opened this issue Jun 26, 2019 · 20 comments
Labels
stale? Issue that may be closed soon due to the original author not responding any more.

Comments

@gjhltn
Copy link

gjhltn commented Jun 26, 2019

Description

Site builds and serves successfully with gatsby build && gatsby serve, but when I copy the built files to an AWS S3 web bucket, the site generates 'resource missing' errors.

(the same AWS bucket has served gatsby sites successfully in the past)

UPDATE: I believe rolling back in same project to

  "dependencies": {
    "gatsby": "2.8.8",
    ...

fixes the issue. 2.9.0 and later all have the problem)

Steps to reproduce

(1)

gatsby new demo
cd demo
gatsby build

(2)
upload files to AWS S3 website-bucket

Expected result

Website should appear as it does from gatsby serve

Actual result

The js does not run. Console shows errors:

Screenshot 2019-06-26 at 13 44 07

According to the 'Network' tab of my browser, all files loaded successfully.

Environment

System:
OS: macOS 10.14.5
CPU: (4) x64 Intel(R) Core(TM) m3-7Y32 CPU @ 1.10GHz
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.4.0 - ~/.nvm/versions/node/v12.4.0/bin/node
Yarn: 1.16.0 - /usr/local/bin/yarn
npm: 6.9.0 - ~/.nvm/versions/node/v12.4.0/bin/npm
Languages:
Python: 2.7.10 - /usr/bin/python
Browsers:
Chrome: 75.0.3770.100
npmPackages:
gatsby: ^2.10.4 => 2.10.4
gatsby-image: ^2.2.3 => 2.2.3
gatsby-plugin-manifest: ^2.2.0 => 2.2.0
gatsby-plugin-offline: ^2.2.0 => 2.2.0
gatsby-plugin-react-helmet: ^3.1.0 => 3.1.0
gatsby-plugin-sharp: ^2.2.1 => 2.2.1
gatsby-source-filesystem: ^2.1.0 => 2.1.0
gatsby-transformer-sharp: ^2.2.0 => 2.2.0
npmGlobalPackages:
gatsby-cli: 2.7.2

@gjhltn gjhltn changed the title Built files fail when deployed to Amazon S3 Built site fails when deployed to Amazon S3 Jun 26, 2019
@gjhltn gjhltn changed the title Built site fails when deployed to Amazon S3 Built site fails when deployed to Amazon S3 in 2.9.0 and later Jun 26, 2019
@gjhltn
Copy link
Author

gjhltn commented Jun 27, 2019

Still fails in 2.11.0

@gjhltn
Copy link
Author

gjhltn commented Jun 29, 2019

Still fails in 2.11.5, but with a different error

Screenshot 2019-06-29 at 21 13 03

(There IS a 404 page)

@KyleAMathews
Copy link
Contributor

Can you investigate more what's happening? gatsbyjs.org is working fine e.g. https://www.gatsbyjs.org/rhhdjd

@gjhltn
Copy link
Author

gjhltn commented Jun 29, 2019

One thing that I do notice is that this error is in the same function as the previous one, loadPage... which might mean it's still the same error after all?

Also here's a difference between the local site and S3: one of the json files from s3 is being sent as an octet stream. I wonder if that would be sufficient to break it?

Screenshot 2019-06-30 at 00 17 12

Screenshot 2019-06-30 at 00 17 29

@gjhltn
Copy link
Author

gjhltn commented Jul 1, 2019

update: yes this indeed seems to be the issue.

manually setting the content type on everything in /page-data/*/*.json to application/json fixes it. it's quite a drag to work through all the json files but it works i think.

i think the issue is this code

const contentType = req.getResponseHeader(`content-type`)

const isJson = contentType && contentType.startsWith(`application/json`)

...which is not unreasonable, it just didnt break before if by chance the server wasnt setting the mime type correctly

@hussainakram
Copy link

hussainakram commented Jul 2, 2019

@KyleAMathews I'm having the exact same issue on production and it seems on Amazon S3/CloudFront its receiving my page-data.json with content-type: text/plain whereas locally its xhr:


prod

and on console I'm getting:

loader.js:172 Uncaught (in promise) Error: 404 page could not be found.

Any idea what might be the cause?

@silviopaganini
Copy link

also having this problem, anyone found a fix?

@gjhltn
Copy link
Author

gjhltn commented Jul 3, 2019

@silviopaganini the fix is in the thread. change the MIME type of each page-data.json to text/json (or if your s3 client lets you, set it during upload). it's annoying im afraid, if you have a large site. good luck

@gjhltn
Copy link
Author

gjhltn commented Jul 3, 2019

@KyleAMathews could this be problem be avoided by changing

const isJson = contentType && contentType.startsWith(application/json) to just check the file extension instead?

@silviopaganini
Copy link

@gswirrl that's happening locally when you build and serve the files with gatsby serve

@silviopaganini
Copy link

OMG

@colbyfayock
Copy link
Contributor

development environment fixes aside, is Gatsby's position that this is an environment issue or will there be thought putting into a gatsby solution? i think this kind of problem creates a higher barrier of entry for newcomers

@KyleAMathews
Copy link
Contributor

is Gatsby's position that this is an environment issue or will there be thought putting into a gatsby solution

The expectation is currently that people’s servers would set the mime type to application/json but yeah — that’s probably too strict given how many variants there is out there (see e.g. https://stackoverflow.com/questions/477816/what-is-the-correct-json-content-type)

Checking the extension in addition to the mime type seems reasonable — would someone like to PR that in?

@wardpeet
Copy link
Contributor

wardpeet commented Jul 4, 2019

I just created a PR that doesn't look at content type but tries to parse the json. This should fix your issues.

@gjhltn
Copy link
Author

gjhltn commented Jul 4, 2019

@wardpeet woah. thats a much better idea than mine. thank you. 🙏

@pieh
Copy link
Contributor

pieh commented Jul 6, 2019

Hey, we just published gatsby@2.13.6 that should fix this. Please give it a go and let us know if it solved the issue

@gjhltn
Copy link
Author

gjhltn commented Jul 6, 2019

@pieh confirmed fixed for me! 🎉 thank you! 👍

@Rajarml
Copy link

Rajarml commented Jul 11, 2019

Our PWA is hosted in Azure websites and we can't upgrade Gatsby higher than 2.9.2 (since the page-data.json change). The issue occurs only after an app deployment (locally everything is fine).
Testing the version 2.13.12 fix the problem :)

@wardpeet
Copy link
Contributor

Seems like we fixed this bug 🎉 let's close 😄

@gatsbot
Copy link

gatsbot bot commented Aug 1, 2019

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.

If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contributefor more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Aug 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale? Issue that may be closed soon due to the original author not responding any more.
Projects
None yet
Development

No branches or pull requests

8 participants