swiper
swiper copied to clipboard
Swiper doesn't work with Typescript + ESM "NodeNext" specifier
Check that this is really a bug
- [X] I confirm
Reproduction link
https://codesandbox.io/s/swiper-esm-nodenext-bug-tfo8uf?file=/src/App.tsx
Bug description
Swiper modules like Pagination or Navigation can't be imported when using TypeScript, ESM and tsconfig with module and moduleResolution set to "NodeNext". A TypeScript error occurs: Cannot find module 'swiper' or its corresponding type declarations.ts(2307)
Expected Behavior
The import should just work.
Actual Behavior
The import doesn't work and TypeScript throws an error.
Swiper version
8.3.2
Platform/Target and Browser Versions
Browser
Validations
- [X] Follow our Code of Conduct
- [X] Read the docs.
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
- [X] Make sure this is a Swiper issue and not a framework-specific issue
Would you like to open a PR for this bug?
- [ ] I'm willing to open a PR
We are using Swiper with React on the server and client. Unfortunately we stumbled over this problem as well, while we started to convert our CommonJS source code to ESM. Any chances to fix your package.json using exports with proper typings references like
Same problem here. Would you accept a PR for this? All exports need to be declared explicitly as @Sebastian-Fitzner noted already.
EDIT: There seems to be more that'd need to be done here. The generated declaration files aren't right and the exports are a bit all over the place atm. ;-).
can confirm! I thought it was a yarn v3 problem
Issue is closed because of outdated/irrelevant/not actual/needed more information/inactivity.
If this issue is still actual and reproducible for latest version of Swiper, please create new issue and fill the issue template correctly:
- Clearly describe the issue including steps to reproduce when it is a bug.
- Make sure you fill in the earliest version that you know has the issue.
- Provide live link or JSFiddle/Codepen or website with issue