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

Typescript Error: "Cannot find module or its corresponding type declarations" #2029

Closed
kimgiutae opened this issue Mar 30, 2023 · 6 comments · Fixed by #2078
Closed

Typescript Error: "Cannot find module or its corresponding type declarations" #2029

kimgiutae opened this issue Mar 30, 2023 · 6 comments · Fixed by #2078

Comments

@kimgiutae
Copy link

Hi devs.

I'm running a react project with next.js v13 with typescript v5. And I keep getting a TS error even with the suggestions of this related issue: #1983.

If compilerOptions.moduleResolution is "node" the ts error is: "Cannot find module 'photoswipe/lightbox' or its corresponding type declarations.ts(2307)"

Is compilerOptions.moduleResolution is "node16" or "nodenext" the ts error is: "The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("photoswipe/lightbox")' call instead. To convert this file to an ECMAScript module, add the field "type": "module" to 'd:/project/package.json'.ts(1479)"

I mean... the code works and I even get types autocompletion, but i dont know the origin of the error. I supose that is related to some kind of incompatibility between compilation sources.

The only solution I find right now is setting a // @ts-ignore in the line above the import.

NEXTJS v13.2.4
REACTJS v18.2.0
TYPESCRIPT v5.0.2
PHOTOSWIPE v5.3.7

@dimsemenov
Copy link
Owner

Hi,

I'll look into it, possibly this will help you for now - #1957 (comment)

@kimgiutae
Copy link
Author

Hi @dimsemenov. Thx for your time.
The solution that recommend the cited comment doesn't work for me.
The error still remains: "Cannot find module 'photoswipe/dist/photoswipe-lightbox.esm.js' or its corresponding type declarations"

@spencerchang
Copy link

Hi @dimsemenov. Thx for your time. The solution that recommend the cited comment doesn't work for me. The error still remains: "Cannot find module 'photoswipe/dist/photoswipe-lightbox.esm.js' or its corresponding type declarations"

Same issue.

@Yama-Tomo
Copy link

same issue.
My workaround was to create the ambient file.

// src/types/photoswipe.d.ts
declare module 'photoswipe/lightbox' {
  import PhotoSwipeLightBox from 'photoswipe/dist/types/lightbox/lightbox'
  export default PhotoSwipeLightBox
}
// src/some.tsx
import PhotoSwipeLightbox from 'photoswipe/lightbox'
...
// pswp is `PhotoSwipe` type
const pswp = new PhotoSwipeLightbox({ ... })

@DigitalNaut
Copy link

Is there a way to integrate this into the main library? It seems that many people are running into this issue

@smoglica
Copy link

The problem seems coming from typesVersions property from package.json

  "typesVersions": {
    "<4.7": {
      "lightbox": [
        "dist/types/lightbox/lightbox.d.ts"
      ]
    }

Right now types are working only with typescript < 4.7. Using * instead of <4.7 should fix the problem, and types will be available for all typescript versions.

torjusb added a commit to torjusb/PhotoSwipe that referenced this issue Nov 28, 2023
Newer versions of TypeScript would not pick up the types when importing from `photoswipe/lightbox` as the types were restricted to version 4.7 or lower.

The types works perfectly fine with newer versions of TS, so by simply removing the restriction everything works as expected.

fixes dimsemenov#2029
dimsemenov pushed a commit that referenced this issue Nov 28, 2023
Newer versions of TypeScript would not pick up the types when importing from `photoswipe/lightbox` as the types were restricted to version 4.7 or lower.

The types works perfectly fine with newer versions of TS, so by simply removing the restriction everything works as expected.

fixes #2029
referee1005 added a commit to referee1005/PhotoSwipe that referenced this issue Nov 6, 2024
Newer versions of TypeScript would not pick up the types when importing from `photoswipe/lightbox` as the types were restricted to version 4.7 or lower.

The types works perfectly fine with newer versions of TS, so by simply removing the restriction everything works as expected.

fixes dimsemenov/PhotoSwipe#2029
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.

6 participants