Skip to content
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

can't access emitted filename if that file was emitted in a file that only exists in manualChunk #4746

Closed
sapphi-red opened this issue Dec 10, 2022 · 4 comments · Fixed by #4761

Comments

@sapphi-red
Copy link
Contributor

sapphi-red commented Dec 10, 2022

Rollup Version

3.7.2

Operating System (or Browser)

stackblitz

Node Version (if applicable)

No response

Link To Reproduction

https://stackblitz.com/edit/rollup-template-9nc4ay?file=rollup.config.js

Expected Behaviour

I expect the filename can be obtained without an error happening.

This config is a weird one. src/foo.js is specified in manualChunks but cannot be referenced from the entrypoint (src/main.js).
I guess this is not intended to be possible. So alternatively, I expect the build fails with an error that tells manualChunks is incorrectly configured.

(I couldn't give a well summarized title)

Actual Behaviour

The following error happens.

[!] (plugin debug) RollupError: Plugin error - Unable to get file name for unknown file "8d016e3f".
RollupError: Plugin error - Unable to get file name for unknown file "8d016e3f".
    at error (file:///home/projects/rollup-template-9nc4ay/node_modules/rollup/dist/shared/rollup.js:210:30)
    at FileEmitter.getFileName (file:///home/projects/rollup-template-9nc4ay/node_modules/rollup/dist/shared/rollup.js:23559:24)
    at Object.renderChunk (file://file:///home/projects/rollup-template-9nc4ay/rollup.config.js:39:39)
    at eval (file:///home/projects/rollup-template-9nc4ay/node_modules/rollup/dist/shared/rollup.js:23915:40)

Could be related to #4744?

Original issue: vitejs/vite#11293

@sapphi-red sapphi-red changed the title can't access emitted filename if that file was emitted in a chunk only exists in manualChunk can't access emitted filename if that file was emitted in a file that only exists in manualChunk Dec 10, 2022
@lukastaegert
Copy link
Member

lukastaegert commented Dec 16, 2022

Turns out the issue here is that we have separate handlers for emitted files between build and generate phase. The reason is that emitted files in one output should not be emitted in another output. So we have one central file-emission-handler during build, and when outputs are generated, all emitted files are copied over from the central handler to the output specific handler.
How does this relate to this issue? In your example, manualChunks triggers the transform hook of a module for the first time while an output is generated. The transform hook, however, relates to the module graph, which is a shared resource between outputs, and therefore uses the shared handler. However, new emissions are currently not copied over again to the outputs.

Now the question is, what should the solution be? Unfortunately, Rollup does not know why a file was emitted. Maybe the file really is needed, who knows? My current ideas for a solution go into the direction of allowing to keep emitting files via transform hooks from the shared handler and then directly copying the file to all outputs. This may not really be "correct" in this case (well, in this case you would not want the file at all), but one idea for a long term solution would be to add an additional flag when emitting assets like "removeIfUnused" that only keeps an emitted file in the output if it is referenced from any chunk. Then in our example, the file would still not be emitted, but we could in general avoid more unnecessary emitted files (think an SVG import that is not actually used etc.). For such a file, this.getFileName() would return null to signify it was not emitted.

Will follow up on this one.

@lukastaegert
Copy link
Member

Fix at #4761

@sapphi-red
Copy link
Contributor Author

Thanks! I tested out that PR and worked as I expected.

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4761 as part of rollup@3.8.0. You can test it via npm install rollup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants