Perfect-scrollbar: perfect_scrollbar_1.default is not a constructor

Created on 14 Nov 2017  路  6Comments  路  Source: mdbootstrap/perfect-scrollbar

In my component i'm trying to initialize the scrollbar after view init

ngAfterViewInit() { this.scrollContainer = this.elemRef.nativeElement.querySelector('.scroll-content'); const ps = new PerfectScrollbar(this.scrollContainer); }

and i got this error: perfect_scrollbar_1.default is not a constructor, what's wrong here?

need more info question

Most helpful comment

Which version of PS are you using? What is your build env?

FYI:

PS provides 2 types of export, one for CommonJS and the other for ES modules:

Build system should tell which script to use. If the error occurs, it may be a build-tool issue. The error can be workarounded with any of followings:

import * as PerfectScrollbar from 'perfect-scrollbar';
const PerfectScrollbar = require('perfect-scrollbar');

All 6 comments

Which version of PS are you using? What is your build env?

FYI:

PS provides 2 types of export, one for CommonJS and the other for ES modules:

Build system should tell which script to use. If the error occurs, it may be a build-tool issue. The error can be workarounded with any of followings:

import * as PerfectScrollbar from 'perfect-scrollbar';
const PerfectScrollbar = require('perfect-scrollbar');

@utatti, thanks for answer, the error will disappear if use this option:
const PerfectScrollbar = require('perfect-scrollbar');

But the scroll but doesn't appear when i scroll, it's always hidden. I checked the css classes, and it's always: "ps ps--active-y", the css styles i also can see, but the scroll but doesn't appear when i scroll, do you know what problem might be in this case?

Thanks a lot!

Please check if perfect-scrollbar.css is correctly imported, and style requirements meet?

Heh, it works and it's nice, but with PS doesn't work more element.scrollIntoView({ behavior: 'smooth' })

Whatever, thanks for help!

Hmm, if element.scrollIntoView({ behavior: 'smooth' }) fires scroll events, it should work either. Anyway, good to hear that the original issue has been resolved.

For multiple elements on page with scroll it won't work ok, because, it'll be initialized just for first element, it can be fixed easy by this way:

const containers = Array.from(document.querySelectorAll('#selector')); containers.forEach(elem => new PerfectScrollbar(elem));

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Brugarolas picture Brugarolas  路  7Comments

MigFerreira picture MigFerreira  路  7Comments

gpluess picture gpluess  路  4Comments

Gurkirat2210 picture Gurkirat2210  路  5Comments

udithachandana picture udithachandana  路  3Comments