Issue 1:
Bug report

What is the current behavior?

This ticket is not critical, since the dist/production env still works, but there seems to be some not needed redundancy.

The map contains the the same chunk-names for many (not all) entries at the first and last position of the arrays.

If the current behavior is a bug, please provide the steps to reproduce.

The easiest way to reproduce it:

clone the neo.mjs repository: https://github.com/neomjs/neo

npm install

npm run build-all

open dist/production/appworker.js

What is the expected behavior?

Chunk-names should be unique for each path / array. One easy way to fix it is probably to convert the array into a Set and back.

it could make sense though to investigate why this is happening

Other relevant information:

webpack version: 5.72.1

Node.js version: v16.2.0

Operating System: Monterey

Additional tools:

Issue 2:
Bug report

(I think this is a bug. It's possible it's a feature I don't yet understand.)

What is the current behavior?

When using the split chunks plugin, the resulting compilation chunks sometimes have duplicate ids. For example, I added this debugging hook to my webpack config:

compiler.hooks.afterEmit.tap("log-dupe-chunks", function(compilation) {
let chunks = compilation.chunks;
let chunkIds = chunks.map(c => c.id);
let dupeChunks = chunks
.filter(c => chunkIds.filter(i => i === c.id).length > 1)
.map(c =>
pick(c, ["id", "ids", "debugId", "name", "entryModule", "files", "rendered", "hash", "contentHash", "renderedHash", "chunkReason", "extraAsync"])
);
if (dupeChunks.length) {
console.log(dupeChunks);
}
});

Resulting in this output:

[ { id: 'vendors~markdownediting~uploader',
ids: [ 'vendors~markdownediting~uploader' ],
debugId: 1011,
name: 'lazy_store',
entryModule: undefined,
files:
[ 'lazy_store.8122ea9e5a55db822e44.js',
'lazy_store.8122ea9e5a55db822e44.js.map' ],
rendered: true,
hash: '8122ea9e5a55db822e44da03c4fa5547',
contentHash: { javascript: '721f86d9054aaadb11d1' },
renderedHash: '8122ea9e5a55db822e44',
chunkReason: undefined,
extraAsync: false },
{ id: 'vendors~markdownediting~uploader',
ids: [ 'vendors~markdownediting~uploader' ],
debugId: 1026,
name: 'vendors~markdownediting~uploader',
entryModule: undefined,
files:
[ 'vendors~markdownediting~uploader.bd57c5c4595c93582c8b.js',
'vendors~markdownediting~uploader.bd57c5c4595c93582c8b.js.map' ],
rendered: true,
hash: 'bd57c5c4595c93582c8b9e692da052d0',
contentHash: { javascript: 'c9f2f1d06758f3a354b1' },
renderedHash: 'bd57c5c4595c93582c8b',
chunkReason: 'split chunk (cache group: vendors) (name: vendors~markdownediting~uploader)',
extraAsync: false } ]

Shouldn't that first chunk have an id of lazy_store ?

I've only seen the duplicate chunk ids where one of the chunks is my code, the other chunk is vendor/node_modules code (see the cache group: vendors bit).

I've also only seen this happen when using recordsPath. If I delete my webpack records & re-build, all the chunk ids are unique.

If the current behavior is a bug, please provide the steps to reproduce.

Sorry, I'm really struggling to narrow this down. It seems to come and go at the whim of whatever heuristics drive SplitChunksPlugin. If someone can confirm this is a bug and it's not immediately obvious why it happens, I'll try harder.

What is the expected behavior?

Presumably all compilation chunks should have unique ids?

Other relevant information:

webpack version: 4.6.0

Node.js version: 8.11.1

Operating System: Docker with node:8.11-alpine

I'm using https://github.com/GProst/webpack-clean-obsolete-chunks, which expects chunks to have unique ids, and ends up accidentally deleting files when they don't. If it turns out that chunks are allowed to have duplicate ids, I'll submit a fix to that.