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

Gatsby ignores custom html.js and static files #3308

Closed
peXed opened this issue Dec 21, 2017 · 15 comments
Closed

Gatsby ignores custom html.js and static files #3308

peXed opened this issue Dec 21, 2017 · 15 comments

Comments

@peXed
Copy link

peXed commented Dec 21, 2017

Hello!

I have a strange issue. I tried to modify the hmtl.js file.
I copied over to src/html.js and added my code (I try to get outdatebrowser into the build http://outdatedbrowser.com/en/).

But Gatsby seems to ignore the file. The custom code doesn't appear in the header and body.

Maybe a related issue I have as well is that Gatsby is not copying over my static files from src/static to the public folder (for example a video in src/static/videos/vid1.mp4). Is this a known issue or do I do something wrong?

Cheers,
Dominik from rocket.works

@KyleAMathews
Copy link
Contributor

html.js goes in src/. The static folder should be in the base of the site (though perhaps src/static makes sense too)

https://www.gatsbyjs.org/docs/adding-images-fonts-files/#using-the-static-folder

@peXed
Copy link
Author

peXed commented Dec 22, 2017

Hello Kyle, thanks for the fast response.

My html.js file is located in the src folder, but it sill gets ignored.
I followed this guide:
https://www.gatsbyjs.org/docs/custom-html/

@KyleAMathews
Copy link
Contributor

You have to restart the develop server as well if you haven't.

@peXed
Copy link
Author

peXed commented Dec 22, 2017

I did. I even deleted the .cache and, to be super safe, the public folder.
But the file gets still ignored. :(

@KyleAMathews
Copy link
Contributor

Could you make a reproduction site? Hard to know why this would be failing without seeing sample code. Lots of people are using custom html.js components.

@themre
Copy link

themre commented Mar 16, 2018

i'm also having the same issue. my package.json has these deps:

"dependencies": {
    "gatsby": "^1.9.232",
    "gatsby-link": "^1.6.39",
    "gatsby-plugin-react-helmet": "^2.0.7",
    "gatsby-plugin-styled-components": "^2.0.9",
    "gatsby-source-prismic": "^0.1.4",
    "i18next": "^10.5.0",
    "i18next-browser-languagedetector": "^2.1.0",
    "i18next-xhr-backend": "^1.5.1",
    "react-helmet": "^5.2.0",
    "react-i18next": "^7.5.0",
    "styled-components": "^3.2.3"
  }

and html.js is inside src folder. I also tried building and no difference. also no changes to any of the gatsby js files. only config has: plugins: ['gatsby-plugin-react-helmet', gatsby-plugin-styled-components]

@themre
Copy link

themre commented Mar 16, 2018

I created simple gatsby site from gatsby-cli and putting html.js into src doesn't work.

@KyleAMathews
Copy link
Contributor

@themre check if there's any errors in the console. Lots of people use custom html.js files (including gatsbyjs.org) so we know it works.

@themre
Copy link

themre commented Mar 17, 2018

There is no error, everything goes through normally. I also put console.log in static-entry and develop-static-entry.js to see if it gets html, but still no output. If you can point me where to look, I can look further.

@themre
Copy link

themre commented Mar 17, 2018

even stranger is if I change default-html.js in .cache folder, it isn't modified, regardless if I run develop or build. Perhaps this is a Windows only issue? Because I also noticed that paths behave strange when I run build. JS src is e.g. /app-234234234.js and if I open .html file, file isn't found because it wants to search on C:\app-23423423424.js.

@m-allanson
Copy link
Contributor

@themre it sounds like there's something strange going on there. Could you push up an example repo to look at?

@themre
Copy link

themre commented Mar 18, 2018

@m-allanson i've setup clean gatsby site by only running gatsby new gatsby-demo and then copying default.html.js to src/html.js. Repo is here: https://github.com/themre/gatsby-demo. If run develop or build, I don't see test.css in my index.html.

@pieh
Copy link
Contributor

pieh commented Mar 18, 2018

@themre your html.js is not valid jsx ( https://github.com/themre/gatsby-demo/blob/master/src/html.js#L28 no closing tag here) - gatsby will ignore it

@themre
Copy link

themre commented Mar 18, 2018

ok, that I get it but what about this one?
<script type="text/javascript">window.$crisp=[];window.CRISP_WEBSITE_ID="9999...";(function(){d=document;s=d.createElement("script");s.src="https://client.crisp.chat/l.js";s.async=1;d.getElementsByTagName("head")[0].appendChild(s);})();</script>

@themre
Copy link

themre commented Mar 18, 2018

For now I have solved this by adding script to react-helmet:
script:{[{"innerHTML": '.....'}]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants