Skip to content

Truncate generated chunk name if too long - #6429

Merged
sokra merged 1 commit into
nextfrom
fix-6426/ENAMETOOLONG
Feb 5, 2018
Merged

sokra merged 1 commit into
nextfrom
fix-6426/ENAMETOOLONG

Conversation

@ooflorent

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

bugfix

Did you add tests for your changes?

yes

If relevant, link to documentation update:

n/a

Summary

If a filename is longer than 255 characters an ENAMETOOLONG error is raised. This PR truncates the chunk name generated by SplitChunksPlugin to 200 characters and happens a unique identifier after to avoid conflicts.

Does this PR introduce a breaking change?

no

Other information

This is more a patch than a proper fix. Ideally webpack should never generate a long filename. However, changing the way filenames are handled is a lot more complex.

Fixes #6426

@ooflorent ooflorent changed the title Truncate chunk generated chunk name if too long Truncate generated chunk name if too long Jan 31, 2018
Comment thread lib/optimize/SplitChunksPlugin.js Outdated
// long, it is truncated and a unique ID is append. The limit
// has been set to 200 to prevent `[name].[chunkhash].[ext]`
// from generating a 256+ character string.
if(name.length > 200) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better limit it to 100 chars, since windows (NTFS) limits total path length to 259 chars.

Comment thread lib/optimize/SplitChunksPlugin.js Outdated
// has been set to 200 to prevent `[name].[chunkhash].[ext]`
// from generating a 256+ character string.
if(name.length > 200) {
name = name.slice(0, 200) + "~" + (++guardID);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The guardID is not a good idea.

This method is called multiple times for the same combination of the chunk (for each module) and should return the same result.

In addition to that this depends on execution timing and makes builds non-deterministic.

Just return undefined in this case, which give the chunk no name, which is fine. Chunks don't need names, it's just for cooler filenames.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative: truncate it and add a hash of the full name, that's deterministic, but not sure how useful this would be.

@TheLarkInn

Copy link
Copy Markdown
Member

@gdborton would you like have input on this? I agree with @sokra that we want to retain as much usefulness as possible.

@ooflorent
ooflorent force-pushed the fix-6426/ENAMETOOLONG branch from c08995c to 48e370e Compare February 2, 2018 08:54
@webpack-bot

Copy link
Copy Markdown
Contributor

@ooflorent Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@sokra Please review the new changes.

@webpack-bot

Copy link
Copy Markdown
Contributor

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

@sokra

sokra commented Feb 5, 2018

Copy link
Copy Markdown
Member

Thanks

@sokra
sokra deleted the fix-6426/ENAMETOOLONG branch February 5, 2018 08:16
pi0 added a commit to nuxt/nuxt that referenced this pull request Jul 2, 2020
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 this pull request may close these issues.

4 participants