Gatsby import
Hello,
so I tried the import with Gatsby but, because its SSR, it can't access the functions needed from the client side. I followed along the steps on the react page: https://splidejs.com/integration-react-splide/
But I only get this error:
ReferenceError: self is not defined
at Object../node_modules/@splidejs/splide/dist/js/splide.esm.js
Could anyone help me set up Splide with Gatsby?
I have the same error, did you resolve this?
Nope. I now use the embla carousel, another project. Maybe I dont understand the fundamentals of Gatsby but I cant get it to work.
This solution works for me, in gatsby-node.js file:
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
if (stage === "build-html") {
actions.setWebpackConfig({
module: {
rules: [
{
test: /@splidejs/,
use: loaders.null(),
},
],
},
})
}
}
Then, in your component add the next lines:
if (typeof window === "undefined") {
return <p>Server Render</p>
}
Src: link
Thx, @subgero, that helps. To add the return statement within render-method of the component where the Splide-component is rendered crucial. I'd recommend to add this info to the main docs, here: https://splidejs.com/integration-react-splide/
@ch12r it would be great but I dont own the project, Im not so smart! :/.
Am I correct in thinking that this essentially forces Splider to render client side?
Either way, the self is not defined error relates to self not being available to NodeJs.
I have posted a fix here: #252, as the same issue interrupts Gridsome build. The end result is a fully working SSR rendered splider.
Close the issue due to the major version update. Feel free to create a new issue or open a new discussion.
Solved the SSR reference error in v3. I made the Splide site by Gatsby. The react component is coming soon, but you can use Splide by creating your component.