Skip to content

window or document is not defined #198

@Lizhooh

Description

@Lizhooh

I want to include some libraries and use cdn.
Where's index.html?
What should I do?

npm start is no error, but npm run build error:

Template execution failed: ReferenceError: window is not defined
  ReferenceError: window is not defined
Template execution failed: ReferenceError: document is not defined
  ReferenceError: document is not defined

code 1 (window is not defined):

import Swiper from 'swiper';

// .... Swiper using window object
componentDidMount() {
  let { options, swiperIsInitialized } = this.props;      
  //  <div className="swiper-container" ref={r => this.root = r}>
  this.swiper = new Swiper(this.root, options);
  this.props.swiperIsInitialized(this.swiper);
}

code 2 (document is not defined):

import './style';
import App from './components/app';

const head = document.querySelector('html > head');

// add css
head.innerHTML += `
    <link href="https://cdn.bootcss.com/material-design-icons/3.0.1/iconfont/material-icons.min.css" rel="stylesheet">
    <link href="https://cdn.bootcss.com/Swiper/3.4.2/css/swiper.min.css" rel="stylesheet">
`;

export default App;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions