Cannot read private member from an object whose class did not declare it
benoitdelorme opened this issue · comments
Describe the bug
I use Lenis in my Nuxt3-Lenis module and since I updated with the latest version of Lenis I have an error when I'm using lenis.start() and lenis.stop(). It worked with version 1.0.27
![Capture d’écran, le 2024-02-15 à 08 03 45](https://private-user-images.githubusercontent.com/561485/305095121-7055d1e7-523b-4d6e-ae57-b60a5f3ddc13.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAyNjMwMzQsIm5iZiI6MTcyMDI2MjczNCwicGF0aCI6Ii81NjE0ODUvMzA1MDk1MTIxLTcwNTVkMWU3LTUyM2ItNGQ2ZS1hZTU3LWI2MGE1ZjNkZGMxMy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzA2JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcwNlQxMDQ1MzRaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT04MmViNzQ0MTljODA4YjNlODI1Y2ZmNmU1ZDIwZWE2OTk0MDgxYmY4ZWZjNTExYzFmNjhmNDI4YzBjMDhkNmUyJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.tgLCuImjNrKqJ2b2jEp-didVVBcaWypCsL8MUjlz1tw)
I tried to fix it but without much success.
start() {
this.isStopped = false // this.#isStopped = false
this.reset()
}
stop() {
this.isStopped = true // this.#isStopped = true
this.animate.stop()
this.reset()
}
You mean calling lenis.start()
throws this error ? Can you provide a codesandbox ? It seems you're trying to change a private property of Lenis.
It might comes from how you use Lenis in your implementation since it works as expected here https://codesandbox.io/p/sandbox/small-cdn-yk9cqy?file=%2Fsrc%2FApp.js%3A8%2C16
i have the same problem. It happens when i call the functions start() and stop()
this is the sandbox: https://codesandbox.io/p/live/4825f9e6-107a-408c-8a57-aa5a1e22db81
I can't access your codesandbox @plcdnl
I'm facing the same issue when calling start()
and stop()
. It seems to happen from Lenis v1.0.35, because v1.0.34 works fine on my end.
I think it comes from this commit, where private properties have been introduced.
According to the MDN Docs about Private Fields, I would suggest accessing these private class properties using this.#isStopped
instead of this.isStopped
for example : https://github.com/darkroomengineering/lenis/blob/main/packages/lenis/src/index.ts#L276
(I'm using Nuxt 3.10.2)
Why is this happening only with nuxt ?
Good question, have you tested it in a vanilla js environment ?
Why is this happening only with nuxt ?
https://codesandbox.io/p/devbox/lenis-nuxt-bug-tfdzlp
here the sandbox. Sorry!
I can't access your sandbox either @clementroche
It seems like codesandbox make draft private by default now
here is @thiervoj : https://codesandbox.io/p/sandbox/small-cdn-yk9cqy?file=%2Fsrc%2FApp.js
can you try outside of defineNuxtPlugin ?
can you try outside of defineNuxtPlugin ?
https://codesandbox.io/p/devbox/lenis-nuxt-bug-forked-9kkc6c?
Ok found, it happens with vue reactive/refs. With simple vars it works without problems
ok that's not ideal anyway, thank you for your feedback, I must find a better way to handle it imo. Imma revert to previous way.
Thank you for your work!
Thank you!
It's fixed in v1.0.37