-
-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
window or document is not defined #198
Comments
There's no need to put those in In class App extends Component {
render() {
return (
<div id="app">
<link href="//cdn.bootcss.com/material-design-icons/3.0.1/iconfont/material-icons.min.css" rel="stylesheet" />
<link href="//cdn.bootcss.com/Swiper/3.4.2/css/swiper.min.css" rel="stylesheet" />
<Header />
<Router onChange={this.handleRoute}>
<Home path="/" />
<Profile path="/profile/" user="me" />
<Profile path="/profile/:user" />
</Router>
</div>
);
}
} For your componentDidMount() {
let { options, swiperIsInitialized } = this.props;
// <div className="swiper-container" ref={r => this.root = r}>
let Swiper = require('swiper');
this.swiper = new Swiper(this.root, options);
this.props.swiperIsInitialized(this.swiper);
} |
Check out https://www.npmjs.com/package/window-or-global :) |
@hassanbazzi Thank you, but ... |
@thangngoc89 ok, thank. |
( ^_^ ), then the solution is:: |
I'm going to put this here because it took me a while to figure out, but it looks like dynamically loading the component that contains the library code that uses In the below example
Folks might find this useful, or also tell me why they think this is a bad idea. |
As the docs say, it's probably better and easier to wrap the specific parts that cannot be prerendered in a window check: |
@rschristian It's an external library, so I don't have access to that code, and when I added that if statement around the component I do control it still threw that error. |
@simonv3 You should be able to wrap it around the import or whatever. Not sure how you're using that lib, but so long as you don't import it, it can't execute and look for |
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:
code 1 (window is not defined):
code 2 (document is not defined):
The text was updated successfully, but these errors were encountered: