question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:7

github_iconTop GitHub Comments

3reactions
subgerocommented, Mar 12, 2021

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

1reaction
animaldcommented, Apr 23, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Importing Assets Directly into Files - Gatsby
There are two major ways to import assets, such as images, fonts, and files, into a Gatsby site. The default path is to...
Read more >
gatsby sass is not working --import error - Stack Overflow
scss' does not contain a default export (imported as 'headerStyles'). I have a header.module.scss and the header.js which contains: import { ...
Read more >
gatsby-plugin-utils - npm
It is called internally by Gatsby to validate each plugin's options when a site is started. Example. import { validateOptionsSchema } from " ......
Read more >
How To Use Static Files in Gatsby | DigitalOcean
Like many popular Static Site Generators, Gatsby embraces the use of dynamic web ... import * as React from "react" import Layout from...
Read more >
How to Set Up Import Aliases for Gatsby | by Malik Elgabroun
The reason why we are setting up import aliases is more to do about readability and the look of our code when importing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found