tholman / cursor-effects

Old-school cursor effects for your browser built with modern JavaScript
https://tholman.com/cursor-effects
3.35k stars 246 forks source link

this is undefined error in last releases #43

Closed revoltek-daniel closed 1 year ago

revoltek-daniel commented 1 year ago

Hello,

since 1.0.5 i get the error message "this is undefined" it looks like it is caused by this commit https://github.com/tholman/cursor-effects/commit/c4b4aef2cd371d2c32b23d903ccb65c0be5a4a64

tholman commented 1 year ago

Could you send over your code in a little demo plz, looking to debug.

revoltek-daniel commented 1 year ago
import {fairyDustCursor} from 'cursor-effects'

fairyDustCursor({colors: ["#ff0000", "#00ff00", "#0000ff"]});

compile this with webpack and you get the undefined error on "this.destroy"

<html>
<head>
    <title>test</title>
    <script src="https://unpkg.com/cursor-effects@latest/dist/browser.js"></script>
<script>
    new cursoreffects.fairyDustCursor({colors: ["#ff0000", "#00ff00", "#0000ff"]});
</script>
</head>
<body></body>
</html>

leads to another "Uncaught TypeError: n is null" errorin browser.js:1:9861

pushed my demo code also to this repo: https://github.com/revoltek-daniel/cursor-test

tholman commented 1 year ago

Ahh, it looks like in test 2 the function needs to be in a window.onload (or in the body) to run after the body exists, I should be able to make a fix for that where there is some kind of wait/check

As for 1, im not quite sure why it won't allow an assignment to this in the compiled version but should be able to figure it out this week/weekend

tholman commented 1 year ago

(the import bug is now fixed), using an onLoad, or calling the create after the body is rendered will fix the rendering for now, until I do something better there.

tholman commented 1 year ago

Feels like the main bug is covered. I will add some documentation to ensure that the function is called when a body exists if its working correctly for you

tholman commented 1 year ago

Fixes out, and docs updated