terser-webpack-plugin: Terser v3.16.0 breaks terser-webpack-plugin

The latest terser update (released an hour ago) breaks this plugin.

  • Operating System:
  • Node Version: 10.12.0
  • NPM Version: 6.4.1
  • webpack Version: 4.29.0
  • terser-webpack-plugin Version: 1.2.1

Expected Behavior

Terser to minify my code

Actual Behavior

ERROR in js/main.6e4faa1e7d31caf0fa3b.js from Terser
TypeError: Cannot read property 'minify' of undefined
    at minify (/<path>/node_modules/terser-webpack-plugin/dist/minify.js:175:23)

How Do We Reproduce?

Delete yarn.lock

Install terser-webpack-plugin and try to run a production build where the plugin is called

workaround

As a workaround for now if you use yarn you can add a resolution to a fixed terser version. Delete yarn.lock first and node_modules

Example (in your package.json)

"resolutions": {
  "terser": "3.14.1"
}

For npm try the suggestion by @odedi

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 160
  • Comments: 54 (4 by maintainers)

Commits related to this issue

Most upvoted comments

A bug in terser 3.16 which was released hours ago.

For npm users run: npm i terser@3.14

For yarn users: add the following field to package.json and then rerun yarn:

"resolutions": {
  "terser": "3.14.1"
}

Solution: npm install terser@3.14.1 --save-dev For me it solves!

I changed _terser.default.minify to _terser.minify and it works

To summarize it: Everybody that gets a CI failure on the master branch or an error on production, probably didn’t commit the lockfile. That’s not how lockfiles work. They are there to fix your dependencies, so every dependency upgrade need to be done manually** in a PR, which is reviewed and tested by CI. This way no broken release (which happen, because everyone makes mistakes) could every break your production environment or even your development workflow.

** There are also services to automate this.

For everyone using npm who can’t wait for update from terser, here is a simple (temporary) fix you can apply:

  1. npm install --save-dev terser@3.14.1 --save-exact
  2. edit package-lock.json > locate: “terser-webpack-plugin” > inside it’s tree: change: “terser”: “^3.8.1” (or whatever), to “terser”: “3.14.1” and make sure there is no “^” in front of the version

Cheers

Hello guys, the same problem for me when running nuxt generate, now I fixed using @TomCosta solution npm install terser@3.14.1 --save-dev, so thanks. Hope this problem will be fixed in the future.

@ksharlandjiev package-lock is generally quite good for applications but not libraries (since you won’t be testing and building using the same dependencies that users of your library will end up with)

Locking the dependencies is useful for libraries too as it makes the build process reproducible.

When doing the above trick, make sure to install the exact version (--save-exact) or else you’ll end up with a broken first level dependency:

npm install terser@3.14.1 --save-dev --save-exact

And your package.json afterwards should mention:

terser: "3.14.1" - there should be NO ^ in front of the 3.

@vladimiry Agree. Default exports and module.exports assignment were mistake.

@huochunpeng the point is that terser made a breaking change without bumping the major version, but just v3.14.1 => v3.16.0. Besides worth taking into the account that it’s not just terser-webpack-plugin depends on terser but many other libraries too.

@afide1 Hey, its been fixed, all you need to do is update terser-webpack-plugin to v1.2.2 +

Locking the dependencies is not that useful for libraries. You rather want to see things break in your CI and be warned about it. If you must lock your dependency to a certain dependencies, this should be the way to go.

@bendg25 look at your package-lock.json and search for “terser”. I have suggested a fix somewhere up in the comments.

@anujladia if you build something on CI servers (Travis, Gitlab, etc) using npm consider executing npm ci there instead of npm install.

@anujladia check my suggestion, I was also with the same case. Install terser 3.14.1 locally with —save-dev, modify package-lock and specify 3.14.1 and not anything else starting with ^ for any package using it

@mdix I am not using terser library directly in my package.json. Third party libraries are using terser, so will this change help me be able to build my web app correctly?

This is also affecting Create React App. See https://github.com/facebook/create-react-app/issues/6334.

Running npm install terser@3.14.1 --save-dev fixed my Nuxt npm run build too. Thank you.

@TomCosta , I literally had this issue about 15 mins ago for an ionic 4 project. Found your solution, which you posted about 10 mins ago and worked perfectly, thanks 😃

Yikes, looks like next.js is broken too 😨