-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Nest deps chunk cannot be loaded when optimizing deps in build mode #13933
Labels
Comments
Start a new pull request in StackBlitz Codeflow. |
9 tasks
Is there an update available for this issue? I am facing this issue when using Cloudscape due to their dynamic imports. |
Closing as the build-time dep-optimization is now removed (#15184). |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Describe the bug
Background
Because I have written some esbuild plugins in the project, I need to keep consistency between the build and dev modes. Therefore, I enabled Optimizing dependencies in build mode.
Actually happen
I executed the command "vite build" some exceptions occurred(The logs section can be seen below), which worked fine in dev mode.
After debugging the vite source code, I found the following:
My dependencies are dynamic import another dependency, but the "optimizedDepInfoFromFile" function cannot find any information and eventually throws 'Something unexpected happened while optimizing' error.
The reason is that the file to be loaded has not been processed by "flattenId," but the files in "depInfoList" have been processed by "flattenId," leading to the inability to locate the file.
In dev mode, when the
optimizedDepsPlugin
fails to find info, it will fallback and load the file from the cache. However, theoptimizedDepsBuildPlugin
has a similar logic, but it immediately throws an error before using the fallback logic.I have found a workaround, which is to add the following configuration in the vite.config.ts file:
By doing this, not only init deps with flattenId, but also in
esbuild.context
entryPoints
will get the flatId, which allows them to be correctly loaded.Expect
Using
vite build
works fine when I enabled Optimizing dependencies in build mode.Other contexts
I would like to attempt to resolve this issue by aligning the fallback load logic of
optimizedDepsBuildPlugin
load hook with the logic used inoptimizedDepsPlugin
.Besides, I have other doubts (which might belong to a separate discussion on another issue). I noticed that the
file
field for thechunks
in the.vite/deps/_metadata.json
is processed withflattenId
. However, the chunk files generated by esbuild on the disk do not undergo theflattenId
process. Is this behavior expected?Reproduction
https://stackblitz.com/edit/vitejs-vite-vttiy9?file=package.json
Steps to reproduce
pnpm i
pnpm run build
Then can see throw Error.
System Info
Used Package Manager
pnpm
Logs
Click to expand!
Validations
The text was updated successfully, but these errors were encountered: