Full reduced test case: https://github.com/OliverJAsh/webpack-flush-chunks-webpack-v5-bug
package.json:
{
"dependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2",
"webpack": "^5.58.0",
"webpack-cli": "^4.9.0",
"webpack-flush-chunks": "^2.0.3"
}
}
webpack.config.js:
module.exports = {
mode: "production",
entry: "./src/entry.js",
optimization: {
chunkIds: 'named',
}
};
src/entry.js:
import(/* webpackChunkName: "routeA" */ './routeA')
import(/* webpackChunkName: "routeB" */ './routeB')
src/routeA.js:
import React from 'react';
import ReactDOM from 'react-dom';
React;
ReactDOM;
src/routeB.js:
import React from 'react';
import ReactDOM from 'react-dom';
React;
ReactDOM;
test.js:
const flushChunks = require("webpack-flush-chunks").default;
const stats = require("./stats.json");
const result = flushChunks(stats, { chunkNames: ["routeA"] });
console.log(result.scripts);
Run these commands:
rm -rf dist
webpack --json=stats.json
node test.js
Expected result:
[ 'routeA.js', 'main.js' ]
Actual result:
[
'vendors-node_modules_react-dom_index_js.js',
'routeA.js',
'main.js'
]
Full reduced test case: https://github.com/OliverJAsh/webpack-flush-chunks-webpack-v5-bug
package.json:{ "dependencies": { "react": "^17.0.2", "react-dom": "^17.0.2", "webpack": "^5.58.0", "webpack-cli": "^4.9.0", "webpack-flush-chunks": "^2.0.3" } }webpack.config.js:src/entry.js:src/routeA.js:src/routeB.js:test.js:Run these commands:
Expected result:
Actual result: