faceyspacey / webpack-flush-chunks

💩 server-to-client chunk discovery + transportation for Universal Rendering
MIT License
355 stars 33 forks source link

webpack v5: missing dynamic chunks generated by `splitChunks` when chunk IDs are strings #104

Open OliverJAsh opened 3 years ago

OliverJAsh commented 3 years ago

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'
]