Estoy tratando de importar una biblioteca dentro de mi paquete y lo intento de todas las formas, pero cada vez que aparece un error.
La biblioteca es Justified-Gallery, pero a veces esto también sucede con otra biblioteca y tengo que entender dónde está el problema.
Estoy usando webpacker con Rails.
Este es mi punto de entrada, y lightGallery , otra biblioteca que estoy usando, está funcionando.
import 'lightgallery/scss/lightgallery-bundle' // init vendor import lightGallery from 'lightgallery' import lgThumbnail from 'lightgallery/plugins/thumbnail' import lgZoom from 'lightgallery/plugins/zoom' window.lgZoom = lgZoom window.lgThumbnail = lgThumbnail window.lightGallery = lightGallery require('justifiedGallery') // init global user javascript import './js/init.js';Init.js es mi script principal
import NavbarSingleTon, { Navbar } from './navbar'; import GallerySingleTon, { Gallery } from './gallery'; (function init() { document.addEventListener('DOMContentLoaded', () => { Navbar.init(); Gallery.init(); }); }());Y finalmente esta es mi galería.js
export class Gallery { constructor($el) { $el.justifiedGallery({ captions: false, lastRow: "hide", rowHeight: 180, margins: 5 }) .on("jg.complete", function () { window.lightGallery( document.getElementById("dmove_gallery"), { autoplayFirstVideo: false, pager: false, galleryId: "dmove", plugins: [lgZoom, lgThumbnail], mobileSettings: { controls: false, showCloseIcon: false, download: false, rotate: false } } ); }); } static init() { $(".gallery-container").each((i, el) => new Gallery($(el))); } }El error que tengo en la consola es
gallery.js:5 Uncaught TypeError: $(...).justifiedGallery is not a function Trato de entender por qué, y require('justifiedGallery' ) requiere este script
intento con
import justifiedGallery from 'justifiedGallery' window.justifiedGallery = justifiedGalleryPero nada... No puedo resolver este problema.