Jump to content
Search Community

TypeError: Cannot read property 'document' of undefined

elseif.io test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi,

 

Loving what you guys are doing here and I'm a massive fan of GSAP :)

 

I am using it in a fairly large project at the moment and all of a sudden I'm getting the below errors. My NPM package imports GSAP via ES imports and works great in my Storybook environment.

 

import 'gsap'
import ScrollToPlugin from 'gsap/umd/ScrollToPlugin'

 

I published a new version of this package recently and all of a sudden, the environment which imports my package (which is a SSR app with Node+React) is complaining about document being undefined. 

 

TypeError: Cannot read property 'document' of undefined

 

The error coming from the minified output of what seems to be the CSSPlugin.js file. 

 

/*!
 * VERSION: 1.20.5
 * DATE: 2018-05-21
 * UPDATES AND DOCS AT: http://greensock.com
 *
 * @license Copyright (c) 2008-2018, GreenSock. All rights reserved.
 * This work is subject to the terms at http://greensock.com/standard-license or for
 * Club GreenSock members, the software agreement that was issued with your membership.
 *
 * @author: Jack Doyle, jack@greensock.com
 */s.d(c,"d",function(){return n}),s.d(c,"e",function(){return r}),s.d(c,"c",function(){return i}),s.d(c,"a",function(){return a}),s.d(c,"b",function(){return u});var n="undefined"!=typeof window?window:e.exports&&void 0!==t?t:void 0,r=function(f){var p={},r=f.document,d=f.GreenSockGlobals=f.GreenSockGlobals||f;if(d.TweenLite)return d.TweenLite;function h(e){var t,n=e.split("."),r=d;for(t=0;t<n.length;t++)r[n[t]]=r=r[n[t]]||{};return r}function c(e){var t,n=[],r=e.length;for(t=0;t!==r;n.push(e[t++]));return n}function m(){}function y(u,c,s,l){this.sc=E[u]?E[u].sc:[],(E[u]=this).gsClass=null,this.func=s;var f=[];
 ...
 *snip*
 ...

 

The error comes from the first reference to `document` in that example above (f.document)

 

Oddly this has been working until I recently upgraded to Webpack 4 & Babel 7 so I suspect that is an avenue to explore but I am just a little lost as to why that impact this.

 

Using latest v2 of GSAP on NPM. I have tried manually forcing `global.document = {}` in my node environment as a temporary measure but that doesn't help.

 

Thanks in advance

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...