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

Imports between chunks are relative to the entrypoint and do not account for directories in the chunk #899

Closed
ggoodman opened this issue Feb 28, 2021 · 1 comment

Comments

@ggoodman
Copy link

When: 1) a dependency graph is such that generated chunks have dependencies on one another; and 2) the chunkNames option introduces additional directory segments, inter-chunk dependencies will have incorrect paths.

Given a chunkNames configuration of chunks/[name]-[hash], an inter-dependency chunk will look like ./chunks/chunk-4VGHEGUY.js instead of ./chunk-4VGHEGUY.js.

I've prepared as minimal of a reproduction as I could in this repl.it.

@evanw
Copy link
Owner

evanw commented Mar 1, 2021

Thanks for the detailed reproduction. This is what I get for trying to cherry-pick a feature from my rewrite branch back to master :)

It should be straightforward to fix, so I'll fix it in the next release. The problem is that import paths are currently embedded in the file before the final hash is calculated so cross-chunk relative imports were not taking the subdirectory into account (since the final path depended on the final hash, which didn't exist yet). I think a sufficient fix should be to provide a fake final path for chunks that haven't computed the final hash yet, just for the purpose of computing the relative path.

This issue is sort of the reason why entry point hashes aren't supported yet. The current code splitting algorithm never generates chunks with import cycles so you can always be sure that the hashes for a chunk's imports will be computed before that chunk's hash needs to be computed. But that doesn't work for entry points because dynamic entry points can import each other. I plan to fix this by embedding import paths in the file after the final hash is calculated instead. The algorithm that I will be using for this in the future is described here: #518 (comment).

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

Successfully merging a pull request may close this issue.

2 participants