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.

server bug: navigator is not defined

See original GitHub issue

Usecase:

import Swiper from "swiper"

export default React.createClass({
   componentDidMount: function(){
      const swiper = new Swiper( this.refs.container, this.props.settings );
   },
});

If you try to render this on server side you’ll get: ReferenceError: navigator is not defined

Problem: Swiper is not isomorphic.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:3
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
droganovcommented, Dec 28, 2015

There is a sense to require it in isomorphic app, that’s not said anyone is going to init it on server. Swiper fails here import Swiper from "swiper"

5reactions
GingerBearcommented, Feb 10, 2017

@renatogalvones this should work

import React, { Component } from 'react';
import 'swiper/dist/css/swiper.min.css'

class App extends Component {
  constructor(props) {
    super(props);
  }

  componentDidMount() {
    const Swiper = require('swiper');
    const swiper = new Swiper(this.refs.container, {});
  }

  render() {
    return (
      <div className="swiper-container" ref="container">
        <div className="swiper-wrapper">
          <div className="swiper-slide"><img src="//placehold.it/500x300" /></div>
          <div className="swiper-slide"><img src="//placehold.it/500x300" /></div>
          <div className="swiper-slide"><img src="//placehold.it/500x300" /></div>
        </div>
        <div className="swiper-pagination"></div>

        <div className="swiper-button-prev"></div>
        <div className="swiper-button-next"></div>
      </div>
    );
  }
}

export default App;

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReferenceError: navigator is not defined · Issue #522 · vercel/swr
Bug report. Description / Observed Behavior. When building the app with NextJS in Jenkins, the build fails with the following error message:.
Read more >
node.js - Fixing "ReferenceError: navigator is not defined"
I'm currently learning how to make PWA. Now I am stuck in the service worker. The logs said that navigator is not defined....
Read more >
Navigator is not defined----bug - Theia Community
navigator is a browser API. If you require code in the backend that ends up executing browser scripts you will get errors.
Read more >
NullEngine giving error, navigator not defined - Bugs
Hi, I do get a following error with the latest Babylonjs 5.0 alpha 44 when I try to run NullEngine: BJS - [23:16:58]:...
Read more >
referenceerror: navigator is not defined next - You.com
Probably this package is not suitable for SSR. It seems like it calls navigator without checking availability of the browser api and it...
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