Universal javascript compatibility
See original GitHub issueMy project is partially rendered server-side. I stumble on importation issue while behind my express server.
import Datamap from 'datamaps';
Triggers an error “ReferenceError: window is not defined”
var d3 = window.d3, topojson = window.topojson;
How do I properly import datamaps ?
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
JavaScript modules via script tag | Can I use... Support tables ...
Loading JavaScript module scripts (aka ES6 modules) using <script type="module"> Includes support for the nomodule attribute. Usage % of. all users, all tracked ......
Read more >Isomorphic JavaScript - Wikipedia
Isomorphic JavaScript, also known as Universal JavaScript, describes JavaScript applications which run both on the client and the server.
Read more >Asm.js, universal compatibility to applications - Scriptol.com
Asm.js is compatible with JavaScript, and provides no additional function but to be validated and compiled the code must only contain the subset...
Read more >The road to universal JavaScript - fettblog.eu
Early on we decided to focus on web standards and support fetch , EcmaScript modules, etc. to make sure we have a common...
Read more >Compatibility - Universal AR
Compatibility. Getting Started · JavaScript · Universal AR. This Zappar platform and Universal AR SDKs work well on the browsers that enjoy the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Guibod that’s a great question - I’ve never tried running it on the server before.
Can you give this branch a shot and see if it gets around the error?
We’re using react with some of the stuff rendered on server side, and we actually managed to run this fine with the current version just by deferring any rendering of maps by calling
require("datamaps")
only when components have mounted (i.e. things got sent to client side). Alternatively if you use webpack you can inject some variables and have a fake “window” object.@markmarkoh I’m a bit confused by your solution. In the code you have
Meaning that you already have proper handling for server side imports.
So what exactly is the point of fetching your dependencies here (outisde the environment check) instead of in the above block?