milespratt / bingmaps-react

An easy to use Bing Maps React component.
https://bingmaps-react.netlify.app
MIT License
21 stars 19 forks source link

Internal error: ReferenceError: document is not defined #76

Closed lcastelnovo-atix closed 8 months ago

lcastelnovo-atix commented 8 months ago

Hello! I am getting this error when rendering the map in a Next.js app

node_modules/react-bingmaps/lib/components/ReactBingmaps/ReactBingmaps.js (49:2) @ new ReactBingmaps ⨯ Internal error: ReferenceError: document is not defined at new ReactBingmaps (./node_modules/react-bingmaps/lib/components/ReactBingmaps/ReactBingmaps.js:66:9)

The code that is crashing is: if (document.querySelector('script[src="' + scriptURL + '"]') === null) { _this.loadScript(scriptURL); window.bingmapsCallback = function () { Microsoft = window.Microsoft; this.afterDependencyLoad(pendingProps); }.bind(_this); } return _this;

the thing is that my build process is failing due to this... anyone can give me a hand? thanks in advance!

lcastelnovo-atix commented 8 months ago

I could figure it out by adding useEffect(() => { if (document) { setIsDocumentReady(true); } }, []);

in my component