Vite can not resolve path pre-bundling Swiper dependencies
See original GitHub issueCheck that this is really a bug
- I confirm
Reproduction link
https://codesandbox.io/s/github/forchel/swiper-test
Bug description
We use Vue 3 with Typescript support, script setup and Swiper 7.3.2 in a project. In our App, we include Swiper Types. If we want to run Vite the following error occurs:
`Pre-bundling dependencies: vue bootstrap vue3-form-validation @fortawesome/fontawesome-svg-core vue-router (…and 15 more) (this will be run only when your dependencies or config have changed)
node_modules/swiper/types/index.d.ts:1:14: error: Could not resolve “./shared” 1 │ export * from ‘./shared’; ╵ ~~~~~~~~~~
node_modules/swiper/types/index.d.ts:2:34: error: Could not resolve “./swiper-class” 2 │ export { default as Swiper } from ‘./swiper-class’; ╵ ~~~~~~~~~~~~~~~~
node_modules/swiper/types/index.d.ts:3:14: error: Could not resolve “./swiper-events” 3 │ export * from ‘./swiper-events’; ╵ ~~~~~~~~~~~~~~~~~
node_modules/swiper/types/index.d.ts:4:14: error: Could not resolve “./swiper-options” 4 │ export * from ‘./swiper-options’; ╵ ~~~~~~~~~~~~~~~~~~
node_modules/swiper/types/index.d.ts:5:14: error: Could not resolve “./modules/public-api” 5 │ export * from ‘./modules/public-api’; ╵ ~~~~~~~~~~~~~~~~~~~~~~
error when starting dev server: Error: Build failed with 5 errors: node_modules/swiper/types/index.d.ts:1:14: error: Could not resolve “./shared” node_modules/swiper/types/index.d.ts:2:34: error: Could not resolve “./swiper-class” node_modules/swiper/types/index.d.ts:3:14: error: Could not resolve “./swiper-events” node_modules/swiper/types/index.d.ts:4:14: error: Could not resolve “./swiper-options” node_modules/swiper/types/index.d.ts:5:14: error: Could not resolve “./modules/public-api” at failureErrorWithLog (C:\projects\tschingo\vue\node_modules\vite\node_modules\esbuild\lib\main.js:1493:15) at C:\projects\tschingo\vue\node_modules\vite\node_modules\esbuild\lib\main.js:1151:28 at runOnEndCallbacks (C:\projects\tschingo\vue\node_modules\vite\node_modules\esbuild\lib\main.js:941:63) at buildResponseToResult (C:\projects\tschingo\vue\node_modules\vite\node_modules\esbuild\lib\main.js:1149:7) at C:\projects\tschingo\vue\node_modules\vite\node_modules\esbuild\lib\main.js:1258:14 at C:\projects\tschingo\vue\node_modules\vite\node_modules\esbuild\lib\main.js:629:9 at handleIncomingPacket (C:\projects\tschingo\vue\node_modules\vite\node_modules\esbuild\lib\main.js:726:9) at Socket.readFromStdout (C:\projects\tschingo\vue\node_modules\vite\node_modules\esbuild\lib\main.js:596:7) at Socket.emit (events.js:315:20) at addChunk (internal/streams/readable.js:309:12)`
Expected Behavior
No problems resolving path.
Actual Behavior
No response
Swiper version
7.3.2
Platform/Target and Browser Versions
Windows, Chrome
Validations
- Follow our Code of Conduct
- Read the docs.
- Check that there isn’t already an issue that request the same feature to avoid creating a duplicate.
- 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
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Add to vite.config
optimizeDeps: { exclude: ["swiper/vue", "swiper/types"], },
Here is probably explanation of problem https://vitejs.dev/guide/dep-pre-bundling.html#the-why
Thank you for your solution. Works for me now.