Jump to content
GreenSock

saki

Uncaught TypeError: Cannot set property window of #<Window> which has only a getter

Recommended Posts

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!

Unbenannt1.PNG

Unbenannt2.PNG

Link to comment
Share on other sites

Hey there!

Have you looked at the installation video?

I haven't seen GSAP being imported directly from node modules like that before.
 

 

  • Like 1
Link to comment
Share on other sites

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

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.

 

 

  • Like 2
Link to comment
Share on other sites

  • 7 months later...

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

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.
×