saki Posted August 2, 2021 Share Posted August 2, 2021 Hey guys! I am a GSAP beginner and need your help. I would like to include GSAP in my animaster.js file via npm and I have GSAP installed and in my node_modules folder. As soon as I want to import GSAP, I get the following error: Uncaught TypeError: Cannot set property window of #<Window> which has only a getter Can you tell me what is the reason for this? :) Thank you! Link to comment Share on other sites More sharing options...
Cassie Posted August 2, 2021 Share Posted August 2, 2021 Hey there! Have you looked at the installation video? I haven't seen GSAP being imported directly from node modules like that before. 1 Link to comment Share on other sites More sharing options...
saki Posted August 4, 2021 Author Share Posted August 4, 2021 It didn't work exactly the path from the video, but the video still helped! My path that finally worked is: import { gsap } from '../node_modules/gsap/index.js'; Thank you Link to comment Share on other sites More sharing options...
OSUblake Posted August 4, 2021 Share Posted August 4, 2021 2 hours ago, saki said: My path that finally worked is: import { gsap } from '../node_modules/gsap/index.js'; Yes, you can't use that import syntax with the dist files without a build tool. Related post. 2 Link to comment Share on other sites More sharing options...
gattingmk Posted March 28, 2022 Share Posted March 28, 2022 In JavaScript almost everything is an object, null and undefined are exception. if a variable has been declared, but has not been assigned a value, is automatically assigned the value undefined . Therefore, if you try to access the value of such variable, it will throw Uncaught TypeError cannot set property ‘0’ of undefined/null . JavaScript null and undefined is one of the main reasons to produce a runtime errors . This happens because you don’t check the value of unknown return variables before using it. If you are not sure a variable that will always have some value, the best practice is to check the value of variables for null or undefined before using them. The standard way to catch null and undefined simultaneously is this: if (variable == null) { // your code here. } Because null == undefined is true, the above code will catch both null and undefined. Also you can write equivalent to more explicit but less concise: if (variable === undefined variable === null) { // your code here. } This should work for any variable that is either undeclared or declared and explicitly set to null or undefined. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now