I have the following code:
import Glide from "@glidejs/glide";
const SectionSlider = () => {
const UNIQUE_CLASS = "random_string"
let MY_GLIDEJS = useMemo(() => {
return new Glide(`.${UNIQUE_CLASS}`, {
perView: itemPerRow,
gap: 32,
bound: true,
breakpoints: {
1280: {
perView: itemPerRow - 1,
},
1024: {
gap: 20,
perView: itemPerRow - 1,
},
768: {
gap: 20,
perView: itemPerRow - 2,
},
640: {
gap: 20,
perView: itemPerRow - 3,
},
500: {
gap: 20,
perView: 1.3,
},
},
});
}, [UNIQUE_CLASS]);
useEffect(() => {
setTimeout(() => {
MY_GLIDEJS.mount();
}, 100);
}, [MY_GLIDEJS, UNIQUE_CLASS]);
return (
<div className={`${UNIQUE_CLASS} flow-root`}>
...
</div>
)};
When rendering this component it throws this error:
TypeError: _glidejs_glide__WEBPACK_IMPORTED_MODULE_3__.default is not a constructor
Additionally the packages I am using (related with this issue) are:
"dependencies": {
"@glidejs/glide": "^3.6.0",
"react": "18.2.0",
...
"devDependencies": {
"@types/glidejs__glide": "^3.6.0",
What is my mistake exactly?
CodePudding user response:
Looks like Glide uses the now defunct module
declaration (see this answer).
From their package.json
"module": "dist/glide.esm.js",
According to Webpack documentation, this should still work but something else seems wrong. I'd try raising a bug.
To work around this for now, you can use the following
import Glide from "@glidejs/glide/dist/glide.modular.esm" // may need ".js"
Note that @types/glidejs__glide
only defines types for:
dist/glide.js
, anddist/glide.modular.esm.js