-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
fix(legacy): error in build with --watch and manifest enabled #14450
fix(legacy): error in build with --watch and manifest enabled #14450
Conversation
Run & review this pull request in StackBlitz Codeflow. |
Do you (vite team) plan on backporting this fix to version 4? I'm currently using https://github.com/adamkoppede/vite/tree/fix/unable-to-get-file-name-error-during-build-watch-vite-4 for the project in which I first encountered the error, in combination with Dockerfile ADD and yarn link. This works for me, but backporting could help others, especially those who need to adjust their server-side logic due to 74fa024. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
If you send a PR to v4 branch, I guess we can. But for 74fa024, you can just set |
Running the build command in version 4.4.9 with --watch flag for a configuration with manifest and legacy-chunks both enabled fails with the following error message: ``` [vite:manifest] Plugin error - Unable to get file name for unknown file "a768f517" ``` A reproduction example for the issue is available online: https://github.com/adamkoppede/reproduce-vite-error-when-building-css-with-watch The (relevant) timeline of the build with --watch is as following: 1. A FileEmitter, let's call this instance FileEmitter(0), is constructed with an undefined base emitter. 2. A FileEmitter, let's call this instance FileEmitter(1), is constructed with FileEmitter(0) as base emitter. 3. A FileEmitter, let's call this instance FileEmitter(2), is constructed with FileEmitter(0) as base emitter. 4. Vite clears `generatedAssets` as part of the `renderStart` function of the `vite:asset` plugin. Let's call the configuration, for which the cleaning occurred, config(1), since it is the first distinct config value we encountered. 5. (If the `buildStart` function of the `vite:asset` plugin is renamed to `renderStart`, vite will clear `generatedAssets` for key config(1) one more time.) 6. FileEmitter(2) gets referenceId "d31f18fc" assigned for file "script.css" 7. ReferenceId "d31f18fc" (src/script.css) is added to `generatedAssets` with key config(1) from inside the `renderChunk` function of the `vite:post-css` plugin 8. FileEmitter(2).getFileName gets successfully called with referenceId "rd31f18fc" from inside `renderChunk` of the `vite:post-css` plugin. 9. FileEmitter(2) gets referenceId "380b7b38" assigned for file "styles.css" 10. ReferenceId "380b7b38" (src/styles.css) is added to `generatedAssets` with key config(1) from inside the `renderChunk` function of the `vite:post-css` plugin 11. FileEmitter(2).getFileName is successfully called with referenceId "380b7b38" from inside `renderChunk` of the `vite:post-css` plugin. 12. `generateBundle` of the `vite:manifest` plugin is executed. `generatedAssets` holds two entries for key config(1): "d31f18fc" (src/script.css) and "380b7b38" (src/styles.css) `generateBundle` issues calls to FileEmitter(2).getFileName for both entries. 13. `generateBundle` of the `vite:manifest` plugin is executed. `generatedAssets` holds two entries for key config(1): "d31f18fc" (src/script.css) and "380b7b38" (src/styles.css) `generateBundle` issues calls to FileEmitter(1).getFileName for both entries. However, there are no entries in FileEmitter(1), thus the calls fail. My first attempt to fix the problem was to extend or change the key of the `generatedAssets` map in a way, that it corresponds to the internal rollup FileEmitter instance that is used. However, I was unable to find a variable with such a property inside the manifest plugin.
f3b4886
to
c6b0af0
Compare
Since major version 5 and a compatible version of the react plugin were released today, I assume that I can just upgrade by using the Thank you for your support. |
The following error was thrown during the build with --watch of a project with plugin-legacy and manifest enabled: ``` [vite:css-post] Plugin error - The "path" argument must be of type string. Received undefined ``` The said project is available at https://github.com/adamkoppede/reproduce-vite-error-when-building-css-with-watch The error is thrown in the `generateBundle` function: `pureCssChunks` contains a chunk with a legacy-javascript filename, which does not exist on the map `prelimaryNameToChunkMap`, since the code is executed for the modern output. The following object values were obtained during a trace right before the assignment of `emptyChunkFiles` inside `generateBundle`: { "prelimaryNameToChunkMap": { "assets/script-!~{001}~.js": "assets/script-121d5cbe.js", "assets/styles-!~{002}~.js": "assets/styles-5ac85f22.js" }, "pureCssChunkNames": [undefined, "assets/styles-5ac85f22.js"], "pureCssChunks": [ { "exports": [], "facadeModuleId": "/reproduce/src/styles.css", "isDynamicEntry": false, "isEntry": true, "isImplicitEntry": false, "name": "styles", "type": "chunk", "dynamicImports": [], "fileName": "assets/styles-legacy-!~{002}~.js" }, { "exports": [], "facadeModuleId": "/reproduce/src/styles.css", "isDynamicEntry": false, "isEntry": true, "isImplicitEntry": false, "name": "styles", "type": "chunk", "dynamicImports": [], "fileName": "assets/styles-!~{002}~.js" } ] }
171d4a4
to
55cf0c6
Compare
Description
Running the build command in version 4.4.9 with --watch flag for a
configuration with manifest and legacy-chunks both enabled fails with
the following error message:
A reproduction example for the issue is available online:
https://github.com/adamkoppede/reproduce-vite-error-when-building-css-with-watch
Additional context
A detailed timeline of the build is available in the commit message body of the first commit: 0f9e22d.
After porting the first patch (1d17388) to current main, the following new error message showed up:
It is just a missing
undefined
check: d839ca8.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).