Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest version of [email protected] broke the build using next-plugin-preact #31

Closed
nickrttn opened this issue May 20, 2021 · 2 comments

Comments

@nickrttn
Copy link

nickrttn commented May 20, 2021

Hi!

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Since the last version of [email protected] when using webpack@5, during a build, I've been seeing the following error:

> Build error occurred
TypeError: Cannot read property 'framework' of undefined
    at Object.webpack (/Users/nick/dev/els-jhp/node_modules/next-plugin-preact/index.js:46:27)

I believe it has been caused by this change: vercel/next.js#25251.

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) {

This issue body was partially generated by patch-package.

@JoviDeCroock
Copy link
Member

JoviDeCroock commented May 21, 2021

Fixed by #32 & published as 3.0.6

@nickrttn
Copy link
Author

Thanks!

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

No branches or pull requests

2 participants