OverlayScrollbars icon indicating copy to clipboard operation
OverlayScrollbars copied to clipboard

Uncaught TypeError: Cannot read property 'querySelectorAll' of undefined

Open asparkam opened this issue 8 years ago • 9 comments

When I try to use it in my React app, I get this error: image

I made import {OverlayScrollbars} from 'overlayscrollbars/js/OverlayScrollbars'; and after mounting all page try this: OverlayScrollbars(document.querySelectorAll('body'), { }); body element is available in this moment and logging into console: image

asparkam avatar Jan 24 '18 15:01 asparkam

After this error occurs, can you initialize a instance of the plugin manually via the console, or will this error show up again? Is it somehow possible to upload a small demo of your project? - It would make it easier for me to fix the issue.

My knowledge with react isn't very good, so I can only guess the error. I'll investigate on this and I'll send tomorrow possible fixes. Please test them and give me feedback if these fixes are working properly or not.

I am sorry, that your experience with my plugin wasn't as good as it should be.

KingSora avatar Jan 24 '18 19:01 KingSora

Similar problem in another plugins: https://github.com/wallabyjs/public/issues/808 https://github.com/akiran/react-highlight/issues/39

I think it is context problem and when I used in your code global.document instead of window,document then error was missing. May be this plugin will be useful: https://www.npmjs.com/package/global

asparkam avatar Jan 28 '18 13:01 asparkam

Please try out this fix, maybe it will work: https://raw.githubusercontent.com/KingSora/KingSora.github.io/master/%238fix.js

KingSora avatar Jan 29 '18 08:01 KingSora

This fix is working when I do import like this import 'overlayscrollbars/js/OverlayScrollbars'; When I try import by this way import OverlayScrollbars from 'overlayscrollbars/js/OverlayScrollbars'; I get empty importing object: image On this way: import {OverlayScrollbars} from 'overlayscrollbars/js/OverlayScrollbars'; I get undefined object: image

asparkam avatar Jan 31 '18 11:01 asparkam

Alright, we're getting closer... please try this: https://raw.githubusercontent.com/KingSora/KingSora.github.io/master/%238fix.js

KingSora avatar Jan 31 '18 12:01 KingSora

This way is working now: import OverlayScrollbars from 'overlayscrollbars/js/OverlayScrollbars';. Thank you!

asparkam avatar Feb 01 '18 07:02 asparkam

Yes! I am glad this bug is fixed now. I'll update the Github repo and the NPM repo later today. The version which will contain this (and some other fixes) will have the version 1.2.3.

Thank you for your cooperation! :)

KingSora avatar Feb 01 '18 08:02 KingSora

Here you go: https://github.com/KingSora/OverlayScrollbars/releases/tag/v1.2.3 NPM is also updated: https://www.npmjs.com/package/overlayscrollbars

KingSora avatar Feb 01 '18 23:02 KingSora

@asparkam Could you share your React integration? Also using React, and wondering how well this plugin works with React?

oyeanuj avatar May 05 '18 23:05 oyeanuj