trvswgnr / bs5-lightbox

A pure JS lightbox gallery plugin for Bootstrap 5 based on the Modal and Carousel components
https://trvswgnr.github.io/bs5-lightbox/
MIT License
129 stars 28 forks source link

Need help for webpack #17

Closed Mordef closed 2 years ago

Mordef commented 2 years ago

What must i do to use this with webpack? I got allways this: Cannot find namespace 'bootstrap'

My testcode

import {bootstrap as bootstrap} from 'bootstrap';
import 'bs5-lightbox';
trvswgnr commented 2 years ago

If importing all modules from Bootstrap 5, do so like this:

import * as bootstrap from 'bootstrap'
import 'bs5-lightbox'

A better approach would be to only import the components you are using, which would utilize Tree Shaking

import { Dropdown, Toast } from 'bootstrap'
import 'bs5-lightbox'
Mordef commented 2 years ago
import * as bootstrap from 'bootstrap'
import 'bs5-lightbox'

Results in

ERROR in [at-loader] ./node_modules/bs5-lightbox/dist/index.d.ts:14:19
    TS2503: Cannot find namespace 'bootstrap'.

ERROR in [at-loader] ./node_modules/bs5-lightbox/dist/index.d.ts:15:22
    TS2503: Cannot find namespace 'bootstrap'.

ERROR in [at-loader] ./node_modules/bs5-lightbox/dist/index.d.ts:18:12
    TS2503: Cannot find namespace 'bootstrap'.

ERROR in [at-loader] ./node_modules/bs5-lightbox/dist/index.d.ts:19:15
    TS2503: Cannot find namespace 'bootstrap'.

ERROR in [at-loader] ./node_modules/bs5-lightbox/dist/index.d.ts:39:31
    TS2503: Cannot find namespace 'bootstrap'.

ERROR in [at-loader] ./node_modules/bs5-lightbox/dist/index.d.ts:39:56
    TS2503: Cannot find namespace 'bootstrap'.

Same with

import { Modal, Carousel, Collapse, Dropdown, Offcanvas } from 'bootstrap';
import 'bs5-lightbox'
trvswgnr commented 2 years ago

This is most likely an issue with your TypeScript config. Without knowing more, I would guess adding this to tsconfig.json might help:

{
    "compilerOptions": {
        "skipLibCheck": true,
    }
}

You might also just exclude the definition file:

{
    "exclude": [
        "node_modules/bs5-lightbox/dist/index.d.ts"
    ]
}
trvswgnr commented 2 years ago

@Mordef is your issue resolved?

Mordef commented 2 years ago

Sory for the late answer. Yes, with "skipLibCheck": true, it works fine