PhotoSwipe icon indicating copy to clipboard operation
PhotoSwipe copied to clipboard

Using PhotoSwipe 5.3 with TypeScript

Open weberhofer opened this issue 1 year ago • 2 comments

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?

weberhofer avatar Jul 22 '22 11:07 weberhofer

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.

dimsemenov avatar Jul 25 '22 17:07 dimsemenov

I have this problem in TypeScript:

TS2307: Cannot find module 'photoswipe/lightbox' or its corresponding type declarations.

image

Generally it works, only these errors are annoying.

rafaucau avatar Aug 04 '22 09:08 rafaucau

Try this:

import PhotoSwipeLightbox from 'photoswipe/dist/photoswipe-lightbox.esm.js';
import 'photoswipe/dist/photoswipe.css';

meetwhere-dev avatar Aug 24 '22 09:08 meetwhere-dev

@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.

Profesor08 avatar Sep 02 '22 15:09 Profesor08

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.

dulacp avatar Jan 14 '23 12:01 dulacp