PhotoSwipe
PhotoSwipe copied to clipboard
Using PhotoSwipe 5.3 with TypeScript
Thank you @dimsemenov for this great software and @irudoy for the Typescript definitions.
Today I have tried to use PhotoSwipe 5.2 (and 5.3) via Typescript. In VC I can simply use the following code:
import PhotoSwipe from "photoswipe";
//...
new PhotoSwipe({});
//...
No errors are displayed. But trying to package it, using typescript 4.7.4, I get the following message:
ERROR in ./src/uz-gallery.ts 7:37-58
Module not found: Error: Package path . is not exported from package /ts/node_modules/photoswipe (see exports field in /ts/node_modules/photoswipe/package.json)
@ ./src/app.ts 11:21-44
Do you have any hint how to solve that issue?
I'm not sure what might be wrong, on my side it works when I try to import it. If you know how package.json
can be improved - feel free to submit a pr.
I have this problem in TypeScript:
TS2307: Cannot find module 'photoswipe/lightbox' or its corresponding type declarations.
Generally it works, only these errors are annoying.
Try this:
import PhotoSwipeLightbox from 'photoswipe/dist/photoswipe-lightbox.esm.js';
import 'photoswipe/dist/photoswipe.css';
@dimsemenov
Cannot find module 'photoswipe/lightbox' or its corresponding type declarations.
Version: 5.3.2
May be this will be helpfull: https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-beta/#packagejson-exports-imports-and-self-referencing
May be something is wrong with rollup
configuration. Try pure tsc
to build.
I also encountered the same error as @Profesor08:
error TS2307: Cannot find module 'photoswipe/lightbox' or its corresponding type declarations.
I realized that my tsconfig.json
was configured for "moduleResolution": "node"
which doesn't support Node-specific features like package.json exports.
To fix it, I change my resolution mode to "moduleResolution": "nodenext"
and that's it.