When I log splitChunks in next-plugin-preact, I'm seeing two different instances of splitChunks, one of which doesn't contain cacheGroups. A simple check fixed the issue and passed the build for me. I'm not sure if this is the right place to fix the issue or it needs to be raised over at Next.js.
A reduced test case of the bug would be to npx create-next-app --example using-preact using-preact-app, install the latest version of Next.js and enable webpack@5 by adding future: { webpack5: true } in next.config.js, then running yarn/npm build.
Here is the diff that solved my problem:
diff --git a/node_modules/next-plugin-preact/index.js b/node_modules/next-plugin-preact/index.js
index e1ba250..30044ef 100644
--- a/node_modules/next-plugin-preact/index.js
+++ b/node_modules/next-plugin-preact/index.js
@@ -40,7 +40,7 @@ module.exports = function withPreact(nextConfig = {}) {
// Move Preact into the framework chunk instead of duplicating in routes:
const splitChunks =
config.optimization && config.optimization.splitChunks;
- if (splitChunks) {
+ if (splitChunks && 'cacheGroups' in splitChunks) {
const cacheGroups = splitChunks.cacheGroups;
const test = /[\\/]node_modules[\\/](preact|preact-render-to-string|preact-context-provider)[\\/]/;
if (cacheGroups.framework) {
Hi!
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch
next-plugin-preact@3.0.4
for the project I'm working on.Since the last version of
next@10.2.2
when usingwebpack@5
, during a build, I've been seeing the following error:I believe it has been caused by this change: https://github.com/vercel/next.js/pull/25251.
When I log
splitChunks
innext-plugin-preact
, I'm seeing two different instances ofsplitChunks
, one of which doesn't containcacheGroups
. A simple check fixed the issue and passed the build for me. I'm not sure if this is the right place to fix the issue or it needs to be raised over at Next.js.A reduced test case of the bug would be to
npx create-next-app --example using-preact using-preact-app
, install the latest version of Next.js and enablewebpack@5
by addingfuture: { webpack5: true }
innext.config.js
, then runningyarn/npm build
.Here is the diff that solved my problem:
This issue body was partially generated by patch-package.