question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vite can not resolve path pre-bundling Swiper dependencies

See original GitHub issue

Check 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:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
krispeklacommented, Dec 22, 2021

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

0reactions
forchelcommented, Feb 21, 2022

Thank you for your solution. Works for me now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting - Vite
Also if there is a dependency loop, a full reload will happen. To solve this, try removing the loop. Build #. Built file...
Read more >
Features | Vite
NPM Dependency Resolving and Pre-Bundling #. Native ES imports do not support bare module imports like the following: js import { someMethod }...
Read more >
Plugin API - Vite
If the plugin doesn't use Vite specific hooks and can be implemented as a ... Users will add plugins to the project devDependencies...
Read more >
Deploying a Static Site - Vite
Vite is installed as a local dev dependency in your project, ... preview is intended for previewing the build locally and not meant...
Read more >
Configuring Vite
The value can be either an absolute file system path or a path relative to project root. Default to .vite when no package.json...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found