Closed davidmusset closed 5 years ago
@davidmusset you mentioned that you're using react router dom right and i saw that you have the following in your package.json
"react-router-dom": "^5.0.0",
"react-router-hash-link": "^1.2.1",
"react-router-hash-link-offset": "^1.0.1",
Gatsby internally uses @reach-router [https://reach.tech/router] and the issue could be with that package, but i'm speculating a bit.
If you need to need to make private routes, that are gated, you can take a look at client-only-paths and simple authentication to see how to setup. But it can be something different alltogether, if you don't mind, can you make a reproduction following these steps so that it can be looked at in more detail.
Hi @jonniebigodes , Thanks for the response
I have tried replacing router-dom by gatsby route but the error was still there.
I reproduced the code and put it on github as per your docs. See here : https://github.com/davidmusset/GatsbyArlina
Let me know if you can find something ?
Many thanks
@davidmusset cloning the repo as i type. I'll take a look into it and report back. Do you mind waiting a bit?
@jonniebigodes ofcourse not
Thanks for the help !
@davidmusset i've been through the reproduction you supplied and it seems that it needs some work so that it can work with gatsby.
I'm assuming based on the installation process i believe that you've initially setup the website with cra(create-react-app) and during that process some issues popped up, there's some vulnerabilities there as you can see below after the package installation is finished.
added 2276 packages from 1037 contributors and audited 58283 packages in 323.901s
found 64 vulnerabilities (63 low, 1 high)
run `npm audit fix` to fix them, or `npm audit` for details
I issued gatsby develop
and i was able to get a development build up and running with some caveats. I'm getting the following:
> gatsby develop
success open and validate gatsby-configs - 0.033 s
success load plugins - 0.125 s
success onPreInit - 0.004 s
success initialize cache - 0.010 s
success copy gatsby files - 0.172 s
success onPreBootstrap - 0.012 s
success source and transform nodes - 0.031 s
success Add explicit types - 0.004 s
success Add inferred types - 0.076 s
success Processing types - 0.047 s
success building schema - 0.229 s
success createPages - 0.001 s
success createPagesStatefully - 0.220 s
success onPreExtractQueries - 0.003 s
success update schema - 0.028 s
success extract queries from components - 0.184 s
success write out requires - 0.027 s
success write out redirect data - 0.002 s
success onPostBootstrap - 0.002 s
⠀
info bootstrap finished - 8.691 s
⠀
success run static queries - 0.049 s — 1/1 23.14 queries/second
success run page queries - 0.136 s — 27/27 206.77 queries/second
⠧ start webpack server
(node:18720) UnhandledPromiseRejectionWarning: localStorage is not defined <--- see here
(node:18720) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:18720) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.jsuccess start webpack server - 3.547 s — 1/1 2.52 pages/second
DONE Compiled successfully in 9760ms 18:25:05
⠀
warn Warning: componentWillUpdate has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.
The reference to localstorage means that gatsby is a server side rendering framework, which means that during the build process the content/pages is build in node and with that access to certain apis is not available and leads to errors. In this mode, the development mode, gatsby takes a more permissive approach and lets you get away with some stuff, so that the development process becomes more streamlined and smoother. That will not happen when you generate a production build with gatsby build
.
I'm going to enumerate some items that need addressing.
src/pages/Components/Footer
<div className ="Footer_RS">
<img className = "RS" src = "img/pictos/RS/FOOTER_INSTAGRAM.jpg" alt="Logo Instagram" onClick={()=> window.open("https://www.instagram.com/arlinaworld/", "_blank")}/>
<img className = "RS" src = "img/pictos/RS/FOOTER_FACEBOOK.jpg" alt="Logo Facebook" onClick={()=> window.open("https://www.facebook.com/ArlinaWorld/", "_blank")}/>
</div>
I would remove the window.open
in the image as it could lead to the what was already mentioned above about access to certain apis during the production build process. A safer approach to this would be to do something like the following:
class Footer extends Component {
handleInstagram = () => {
if (typeof window !== `undefined`) {
window.open("https://www.instagram.com/arlinaworld/", "_blank")
}
}
handleFacebook = () => {
if (typeof window !== `undefined`) {
window.open("https://www.facebook.com/ArlinaWorld/", "_blank")
}
}
render() {
return (
<div className="Footer">
<p style={{ margin: 0 }}> © Arlina 2019 </p>
<div className="Footer_RS">
<img
className="RS"
src="img/pictos/RS/FOOTER_INSTAGRAM.jpg"
alt="Logo Instagram"
onClick={this.handleInstagram}
/>
<img
className="RS"
src="img/pictos/RS/FOOTER_FACEBOOK.jpg"
alt="Logo Facebook"
onClick={this.handleFacebook}
/>
</div>
<Link to="/mentions"> Mentions Legales</Link> |
<Link to="/CGV"> CGV</Link>
</div>
)
}
}
....
With this small change to the component, it implements a safeguard so that when it will be built it will not break, but be available when you or the person that visits the page can interact with the image.
src/Components/Layout/Header.js
, src/Components/Layout/HeaderPaiement.js
, src/Components/Layout/HeaderPerso.js
.src/pages/Component/Pages/Achat.js
, src/pages/Components/Pages/BillingForm.js
, src/pages/Components/Pages/ChoixLivre.js
, src/pages/Components/Pages/HomePage.js
.src/pages/Components/Navigation.js
, basically what you're doing here, in a nutshell is what gatsby does for you. You don't actually need the routing setup you have there. That setup is required in for instance create-react-app, but not here, of the top of my head, you would only need to create that type of routing if you had for instance a some sort of authentication setup which it seems you don't have at the moment, more context on that here and here.pages
folder should only contain the react components that will be used as pages for the website and leave other items out of it. There's some caveats to this, but for this particular case that's what should only be there, meaning the reducers folder and img folder for instance should be outside and same as ReduxWrapper.js
, me personally i would group the redux related items in a folder called redux-data
or something similar directly and move all of the redux related stuff there.redux-storage-engine-localstorage
and 'redux-storage
are not actually ssr friendly. You have to make some adjustments to the ReduxWrapper.js
file and probably you have to create a gatsby-node.js
to make them compliant with gatsby, more on that here.If you'll allow me and don't get me wrong on this, i've checked the website based on the development mode and it looks really nice. But i would check what you had earlier before moving into gatsby and outline what should be a page and what should be a component that a page will displays and make the necessary changes, also i would take a look at how the images are added into the page/component, as they are not being displayed.
Sorry for not offering you more simple solution to your issue, but this something that needs some additional work correctly with gatsby.
Thanks for your help, that's really helpful. I'm still pretty new to react which explains why i'm not familiar with all these issues. But thanks for addressing, I will correct all this and hopefully build back gatbsy again successfully.
Thanks again
Le lun. 30 sept. 2019 à 21:51, jonniebigodes notifications@github.com a écrit :
@davidmusset https://github.com/davidmusset i've been through the reproduction you supplied and it seems that it needs some work so that it can work with gatsby.
I'm assuming based on the installation process i believe that you've initially setup the website with cra(create-react-app) and during that process some issues popped up, there's some vulnerabilities there as you can see below after the package installation is finished.
added 2276 packages from 1037 contributors and audited 58283 packages in 323.901s
found 64 vulnerabilities (63 low, 1 high)
run
npm audit fix
to fix them, ornpm audit
for detailsI issued gatsby develop and i was able to get a development build up and running with some caveats. I'm getting the following:
gatsby develop
success open and validate gatsby-configs - 0.033 s
success load plugins - 0.125 s
success onPreInit - 0.004 s
success initialize cache - 0.010 s
success copy gatsby files - 0.172 s
success onPreBootstrap - 0.012 s
success source and transform nodes - 0.031 s
success Add explicit types - 0.004 s
success Add inferred types - 0.076 s
success Processing types - 0.047 s
success building schema - 0.229 s
success createPages - 0.001 s
success createPagesStatefully - 0.220 s
success onPreExtractQueries - 0.003 s
success update schema - 0.028 s
success extract queries from components - 0.184 s
success write out requires - 0.027 s
success write out redirect data - 0.002 s
success onPostBootstrap - 0.002 s
⠀
info bootstrap finished - 8.691 s
⠀
success run static queries - 0.049 s — 1/1 23.14 queries/second
success run page queries - 0.136 s — 27/27 206.77 queries/second
⠧ start webpack server
(node:18720) UnhandledPromiseRejectionWarning: localStorage is not defined <--- see here
(node:18720) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:18720) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.jsuccess start webpack server - 3.547 s — 1/1 2.52 pages/second
DONE Compiled successfully in 9760ms 18:25:05
⠀
warn Warning: componentWillUpdate has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.
The reference to localstorage means that gatsby is a server side rendering framework, which means that during the build process the content/pages is build in node and with that access to certain apis is not available and leads to errors. In this mode, the development mode, gatsby takes a more permissive approach and lets you get away with some stuff, so that the development process becomes more streamlined and smoother. That will not happen when you generate a production build with gatsby build.
I'm going to enumerate some items that need addressing.
In the file src/pages/Components/Footer
window.open("https://www.instagram.com/arlinaworld/", "_blank")}/> window.open("https://www.facebook.com/ArlinaWorld/", "_blank")}/>I would remove the window.open in the image as it could lead to the what was already mentioned above about access to certain apis during the production build process. A safer approach to this would be to do something like the following:
class Footer extends Component {
handleInstagram = () => {
if (typeof window !== `undefined`) { window.open("https://www.instagram.com/arlinaworld/", "_blank") }
}
handleFacebook = () => {
if (typeof window !== `undefined`) { window.open("https://www.facebook.com/ArlinaWorld/", "_blank") }
}
render() {
return ( <div className="Footer"> <p style={{ margin: 0 }}> © Arlina 2019 </p> <div className="Footer_RS"> <img className="RS" src="img/pictos/RS/FOOTER_INSTAGRAM.jpg" alt="Logo Instagram" onClick={this.handleInstagram} /> <img className="RS" src="img/pictos/RS/FOOTER_FACEBOOK.jpg" alt="Logo Facebook" onClick={this.handleFacebook} /> </div> <Link to="/mentions"> Mentions Legales</Link> | <Link to="/CGV"> CGV</Link> </div> )
}
} ....
With this small change to the component, it implements a safeguard so that when it will be built it will not break, but be available when you or the person that visits the page can interact with the image.
- The same logic needs to be applied to src/Components/Layout/Header.js, src/Components/Layout/HeaderPaiement.js, src/Components/Layout/HeaderPerso.js.
- Also in src/pages/Component/Pages/Achat.js, src/pages/Components/Pages/BillingForm.js, src/pages/Components/Pages/ChoixLivre.js, src/pages/Components/Pages/HomePage.js.
- Also checking src/pages/Components/Navigation.js, basically what you're doing here, in a nutshell is what gatsby does for you. You don't actually need the routing setup you have there. That setup is required in for instance create-react-app, but not here, of the top of my head, you would only need to create that type of routing if you had for instance a some sort of authentication setup which it seems you don't have at the moment, more context on that here https://www.gatsbyjs.org/docs/routing/ and here https://www.gatsbyjs.org/blog/2019-07-11-user-testing-accessible-client-routing/#what-is-client-side-routing .
- Also if you don't mind take a look at this https://www.gatsbyjs.org/docs/gatsby-project-structure/, as it explains the folder structure/organization that gatsby uses. After trying some workarounds on your project i ran into some issues based on the current structure you have. Technically the pages folder should only contain the react components that will be used as pages for the website and leave other items out of it. There's some caveats to this, but for this particular case that's what should only be there, meaning the reducers folder and img folder for instance should be outside and same as ReduxWrapper.js, me personally i would group the redux related items in a folder called redux-data or something similar directly and move all of the redux related stuff there.
- One final thing, the packages redux-storage-engine-localstorage and 'redux-storage are not actually ssr friendly. You have to make some adjustments to the ReduxWrapper.js file and probably you have to create a gatsby-node.js to make them compliant with gatsby, more on that here https://www.gatsbyjs.org/docs/debugging-html-builds/.
If you'll allow me and don't get me wrong on this, i've checked the website based on the development mode and it looks really nice. But i would check what you had earlier before moving into gatsby and outline what should be a page and what should be a component that a page will displays and make the necessary changes, also i would take a look at how the images are added into the page/component, as they are not being displayed.
Sorry for not offering you more simple solution to your issue, but this something that needs alot of work correctly with gatsby.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/gatsbyjs/gatsby/issues/17991?email_source=notifications&email_token=ALDG2SANKK7M5KFJLYKB4OLQMJKEPA5CNFSM4I3ZSKXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7637YQ#issuecomment-536723426, or mute the thread https://github.com/notifications/unsubscribe-auth/ALDG2SAZNW2ECLZ23YCQARDQMJKEPANCNFSM4I3ZSKXA .
@davidmusset no need to thank, i'm sorry that was not more helpfull, when you're able feel free to close this issue. Should more issues arise feel free to open it up then or create a new issue.
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/contribute for more information about opening PRs, triaging issues, and contributing!
Thanks for being a part of the Gatsby community! 💪💜
Hey again!
It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.
Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY
. Please feel free to reopen this issue or create a new one if you need anything else.
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/contribute for more information about opening PRs, triaging issues, and contributing!
Thanks again for being part of the Gatsby community!
@davidmusset you mentioned that you're using react router dom right and i saw that you have the following in your package.json
"react-router-dom": "^5.0.0", "react-router-hash-link": "^1.2.1", "react-router-hash-link-offset": "^1.0.1",
Gatsby internally uses @reach-router [https://reach.tech/router] and the issue could be with that package, but i'm speculating a bit.
If you need to need to make private routes, that are gated, you can take a look at client-only-paths and simple authentication to see how to setup. But it can be something different alltogether, if you don't mind, can you make a reproduction following these steps so that it can be looked at in more detail.
In my case, changing from import { Link } from react-router-dom
to import { Link } from @reach/router
, solved the issue!
Thanks!
Description
Hello,
I'm having troubles building my gatsby project. Development is working fine, but when i try to build, I get an error :
I tried everything but I have no idea how to debug it.
Steps to reproduce
Below is my code. I have basically a static website using redux and react router dom to navigate. I had previously an error when building : "couldn't find the store" which is why I had to create both gatsby-browser and gatsby-ssr to enclose the Provider.
index.js
ReduxWrapper
gatsby-browser & gatsby-ssr (identicals)
export { default as wrapRootElement } from './src/pages/ReduxWrapper';
My package.json :
Expected result
It should build normally
Actual result
I get an error when 'building static HTML for pages'
Environment
System: OS: Windows 10 CPU: (4) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz Binaries: Yarn: 1.16.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.7.0 - C:\Program Files\nodejs\npm.CMD Languages: Python: 2.7.15 Browsers: Edge: 44.18362.329.0 npmPackages: gatsby: ^2.15.28 => 2.15.28 gatsby-plugin-mailchimp: ^5.1.2 => 5.1.2 gatsby-plugin-react-helmet: ^3.1.10 => 3.1.10 gatsby-plugin-stripe: ^1.2.3 => 1.2.3
Many thanks for the help