Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using PhotoSwipe 5.3 with TypeScript #1951

Closed
weberhofer opened this issue Jul 22, 2022 · 5 comments · Fixed by #1957
Closed

Using PhotoSwipe 5.3 with TypeScript #1951

weberhofer opened this issue Jul 22, 2022 · 5 comments · Fixed by #1957

Comments

@weberhofer
Copy link

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?

@dimsemenov
Copy link
Owner

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.

@rafaucau
Copy link

rafaucau commented Aug 4, 2022

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.

@meetwhere-dev
Copy link

Try this:

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

@Profesor08
Copy link

Profesor08 commented Sep 2, 2022

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

@dulacp
Copy link

dulacp commented Jan 14, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants
@dulacp @weberhofer @dimsemenov @Profesor08 @rafaucau @meetwhere-dev and others