Next-pwa: terser-webpack-plugin with Next.js + Webpack 4

Created on 10 Apr 2021  路  2Comments  路  Source: shadowwalker/next-pwa

Summary

I'm using Next.js with Webpack 4 and when I add a fallback page to pages/_offline, terser-webpack-plugin gives the error below:

TypeError: Cannot read property 'javascript' of undefined
at /Users/xxxxxxxxx/node_modules/terser-webpack-plugin/dist/index.js:572:38

I searched for the issue and terser-webpack-plugin@5+ is for Webpack 5 and is not compatible with Webpack 4.

How To Reproduce

Steps to reproduce the behavior:

  1. Use [email protected] which has a dependency for terser-webpack-plugin: "^5.1.1" (Only compatible with Webpack 5)
  2. Use next.js with Webpack 4
  3. Add a fallback page to pages/_offline.js
  4. Get error while building the app.
bug

All 2 comments

Unfortunately this is a unsolvable problem, if I don't add terser-webpack-plugin as dependency in next-pwa. Other folks will see another build error.
Can you try to use {future: webpack5: true} in your project or try install the lower version of terser-webpack-plugin by yarn install [email protected] to mitigate the issue you have encountered?

I upgraded to Webpack 5. It is working properly now. Thanks for the reply @shadowwalker.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Garlink picture Garlink  路  4Comments

LucasMallmann picture LucasMallmann  路  4Comments

flamedmg picture flamedmg  路  4Comments

louisbirla picture louisbirla  路  5Comments

paales picture paales  路  4Comments