WebpackError: ReferenceError: document is not defined
See original GitHub issueHi! First of all, thank you for this neat library.
I’m using it with gatsby. I’m instantiating it in useEffect like this
const scroll = new LocomotiveScroll({
el: scrollRef.current,
smooth: true,
smoothMobile: true,
})
Then I create the ref
const scrollRef = useRef(null)
and assign it to my container
<div ref={scrollRef}></div>
So far so good, it works in development mode in gatsby (so gatsby develop
).
The problem arises when I go to production, so with gatsby build
.
WebpackError: ReferenceError: document is not defined
- locomotive-scroll.esm.js:151 Module../node_modules/locomotive-scroll/dist/locomotive-scroll.esm.js
node_modules/locomotive-scroll/dist/locomotive-scroll.esm.js:151:1
- index.js:1 Module../src/pages/index.js
src/pages/index.js:1:1
- interopRequireDefault.js:7 Object.Module._extensions..js
node_modules/@babel/runtime/helpers/interopRequireDefault.js:7:1
Any thoughts? Thank you!
Cheers.
Edit: I’ve found this, but It’s not working, and this, but I’m not sure how to make it working with locomotive
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
reactjs - WebpackError: ReferenceError: document is not defined
I am getting an error building my project on netlify (WebpackError: ReferenceError: document is not defined). In develop works fine!
Read more >WebpackError: ReferenceError: document is not defined - IE ...
Steps to reproduce. Running gatsby build within project folder after declaring const isIE = /*@cc_on! · Expected result. Site builds without ...
Read more >How to fix 'document not defined' in Gatsby Build
The error document is not defined or window is not defined you see when building a gatsby project is as a result of...
Read more >How to fix ReferenceError: Document is not defined ... - Sabe.io
The most common reason for getting the reference error while on the browser is when you try to access the document object too...
Read more >How To Fix ReferenceError document is not defined ... - Isotropic
If you are trying to use the document object and receiving a ReferenceError: document is not defined error then there is a good...
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 FreeTop 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
Top GitHub Comments
Solved! After tried many times with the links I posted, I’ve found a more easy way: basically when the component is mounted, import the module/library. This will fix the problem relate to ssr - see here
So
FYI if you want to fix the build issue without having to load the script asynchronously, add this to gatsby-node.js