You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have created a Mono-Repo with a Library and a Vite-Frontend consuming said Library.
The Library contains a module I import into the Frontend using the ?url suffix to get the Module URL — as a result the module get added to the dist/assets directory, as expected.
I expect Vite to also include any dependencies the ?url-imported Module might contain.
Vite however does not copy over the ?url-imported Module's dependencies.
Run npm run build. This will build both animations and vite-frontend.
Run npm run host. This will create a local server on Port 1234 serving packages/vite-frontend/dist.
You should see an Element with the Message An error occurred while loading the animation..
Opening the Console, you will see that GET http://localhost:1234/assets/makeScene2D-d2e6cdaa.js has failed.
Stop the Server and run npm run copy-makeScene2D. This will simply copy the file from packages/animations/dist/makeScene2D-... to packages/vite-frontend/dist/assets.
Restart the Server with npm run host.
A primitive animation should be playable.
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
Under the premise of this issue, it seems that vite will handle the modules imported from ?url as asset resources, which can be seen as a replication behavior rather than a packaging behavior.
Here is a simple hack to bypass the behavior of ?url, not recommended.
// build `animations/dist/animation1` module.constmodules=import.meta.glob(['animations/dist/animation1']);// get the path of the built module.constimportPathRegex=/import\(['"]([^'"]+)['"]\)/;constimportStatement=Object.values(modules)[0].toString();constmatch=importStatement.match(importPathRegex);letsourceUrl='';if(match){constpath=match[1];sourceUrl=path;}
Describe the bug
I have created a Mono-Repo with a Library and a Vite-Frontend consuming said Library.
The Library contains a module I import into the Frontend using the
?url
suffix to get the Module URL — as a result the module get added to thedist/assets
directory, as expected.I expect Vite to also include any dependencies the
?url
-imported Module might contain.Vite however does not copy over the
?url
-imported Module's dependencies.Reproduction
https://github.com/WaldemarLehner/vite-url-import-issue-repo
Steps to reproduce
Inside the project root, run
npm i
Run
npm run build
. This will build bothanimations
andvite-frontend
.Run
npm run host
. This will create a local server on Port 1234 servingpackages/vite-frontend/dist
.You should see an Element with the Message An error occurred while loading the animation..
Opening the Console, you will see that
GET http://localhost:1234/assets/makeScene2D-d2e6cdaa.js
has failed.Stop the Server and run
npm run copy-makeScene2D
. This will simply copy the file frompackages/animations/dist/makeScene2D-...
topackages/vite-frontend/dist/assets
.Restart the Server with
npm run host
.A primitive animation should be playable.
System Info
Used Package Manager
npm
Logs
Click to expand!
Validations
The text was updated successfully, but these errors were encountered: