Error In Runtime From Terser During Build --prod
Solution 1
It seems to be a problem with the recently released version 3.16 of Terser, here's the related issue in Terser and in Terser as a Webpack plugin.
In this VueJS issue they recommended to downgrade it to version 3.14.1. You can do it looking for the line in package.json
containing "terser"
and pin it as follows:
"terser": "3.14.1",
Solution 2
As Pietro Saccardi said, by now, it's necessary to fix the Terser version to 3.14.1 in the package.json as follows:
"terser": "3.14.1"
Don't use the ^
in the version or it could upgrade to 3.16.
Solution 3
For Angular prod build, this fixed it for me:
npm install --save-exact --save [email protected]
Solution 4
I'm in Angular 11, in my case it gave the same error, but it was my mistake: in angular.json I didn't import the styles and scripts correctly ("styles": [], "scripts": []),always check if the imports of your project are correct, because if it is wrong, this same error will appear.
Solution 5
To resolve the angular prod build issue, we need to fix the version of terser and terser-webpack-plugin to 3.14.1 in the package-lock.json. Below is what my looks like. Finally the production build is working for me.
"terser": {
"version": "3.14.1",
"resolved": "https://registry.npmjs.org/terser/-/terser-3.14.1.tgz",
"integrity": "sha512-NSo3E99QDbYSMeJaEk9YW2lTg3qS9V0aKGlb+PlOrei1X02r1wSBHCNX/O+yeTRFSWPKPIGj6MqvvdqV4rnVGw==",
"dev": true,
"requires": {
"commander": "2.17.1",
"source-map": "0.6.1",
"source-map-support": "0.5.9"
},
"dependencies": {
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"dev": true
}
}
},
"terser-webpack-plugin": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-1.1.0.tgz",
"integrity": "sha512-61lV0DSxMAZ8AyZG7/A4a3UPlrbOBo8NIQ4tJzLPAdGOQ+yoNC7l5ijEow27lBAL2humer01KLS6bGIMYQxKoA==",
"dev": true,
"requires": {
"cacache": "11.3.2",
"find-cache-dir": "2.0.0",
"schema-utils": "1.0.0",
"serialize-javascript": "1.6.1",
"source-map": "0.6.1",
"terser": "3.14.1",
"webpack-sources": "1.3.0",
"worker-farm": "1.6.0"
},
"dependencies": {
"cacache": {
"version": "11.3.2",
"resolved": "https://registry.npmjs.org/cacache/-/cacache-11.3.2.tgz",
"integrity": "sha512-E0zP4EPGDOaT2chM08Als91eYnf8Z+eH1awwwVsngUmgppfM5jjJ8l3z5vO5p5w/I3LsiXawb1sW0VY65pQABg==",
"dev": true,
"requires": {
"bluebird": "3.5.3",
"chownr": "1.1.1",
"figgy-pudding": "3.5.1",
"glob": "7.1.3",
"graceful-fs": "4.1.15",
"lru-cache": "5.1.1",
"mississippi": "3.0.0",
"mkdirp": "0.5.1",
"move-concurrently": "1.0.1",
"promise-inflight": "1.0.1",
"rimraf": "2.6.3",
"ssri": "6.0.1",
"unique-filename": "1.1.1",
"y18n": "4.0.0"
}
},
"find-cache-dir": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-2.0.0.tgz",
"integrity": "sha512-LDUY6V1Xs5eFskUVYtIwatojt6+9xC9Chnlk/jYOOvn3FAFfSaWddxahDGyNHh0b2dMXa6YW2m0tk8TdVaXHlA==",
"dev": true,
"requires": {
"commondir": "1.0.1",
"make-dir": "1.3.0",
"pkg-dir": "3.0.0"
}
},
"find-up": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz",
"integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==",
"dev": true,
"requires": {
"locate-path": "3.0.0"
}
},
"locate-path": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz",
"integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==",
"dev": true,
"requires": {
"p-locate": "3.0.0",
"path-exists": "3.0.0"
}
},
"lru-cache": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz",
"integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==",
"dev": true,
"requires": {
"yallist": "3.0.3"
}
},
"mississippi": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/mississippi/-/mississippi-3.0.0.tgz",
"integrity": "sha512-x471SsVjUtBRtcvd4BzKE9kFC+/2TeWgKCgw0bZcw1b9l2X3QX5vCWgF+KaZaYm87Ss//rHnWryupDrgLvmSkA==",
"dev": true,
"requires": {
"concat-stream": "1.6.2",
"duplexify": "3.6.1",
"end-of-stream": "1.4.1",
"flush-write-stream": "1.0.3",
"from2": "2.3.0",
"parallel-transform": "1.1.0",
"pump": "3.0.0",
"pumpify": "1.5.1",
"stream-each": "1.2.3",
"through2": "2.0.5"
}
},
"p-limit": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.1.0.tgz",
"integrity": "sha512-NhURkNcrVB+8hNfLuysU8enY5xn2KXphsHBaC2YmRNTZRc7RWusw6apSpdEj3jo4CMb6W9nrF6tTnsJsJeyu6g==",
"dev": true,
"requires": {
"p-try": "2.0.0"
}
},
"p-locate": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz",
"integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==",
"dev": true,
"requires": {
"p-limit": "2.1.0"
}
},
"p-try": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.0.0.tgz",
"integrity": "sha512-hMp0onDKIajHfIkdRk3P4CdCmErkYAxxDtP3Wx/4nZ3aGlau2VKh3mZpcuFkH27WQkL/3WBCPOktzA9ZOAnMQQ==",
"dev": true
},
"pkg-dir": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-3.0.0.tgz",
"integrity": "sha512-/E57AYkoeQ25qkxMj5PBOVgF8Kiu/h7cYS30Z5+R7WaiCCBfLq58ZI/dSeaEKb9WVJV5n/03QwrN3IeWIFllvw==",
"dev": true,
"requires": {
"find-up": "3.0.0"
}
},
"pump": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
"integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==",
"dev": true,
"requires": {
"end-of-stream": "1.4.1",
"once": "1.4.0"
}
},
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"dev": true
},
"ssri": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.1.tgz",
"integrity": "sha512-3Wge10hNcT1Kur4PDFwEieXSCMCJs/7WvSACcrMYrNp+b8kDL1/0wJch5Ni2WrtwEa2IO8OsVfeKIciKCDx/QA==",
"dev": true,
"requires": {
"figgy-pudding": "3.5.1"
}
},
"yallist": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.3.tgz",
"integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==",
"dev": true
}
}
}
Related videos on Youtube
Mathias
Started working with dumb terminals a long long time ago doing Cobol on a mainframe. Morphing through many different technologies over the decades. Currently working primarily with Angular.
Updated on June 04, 2022Comments
-
Mathias almost 2 years
I have updated everything Angular and am now getting the error below (4x) when I
"Build --prod"No errors if I remove --prod
I have no real code in this app. It is just a starter shell.
Any suggestions on what to look into?
ERROR in runtime.82c6613acef8f7246fe8.js from Terser TypeError: Cannot read property 'minify' of undefined at minify (/Users/puser/Dropbox/AngularApps/GenesisFYI-v06/node_modules/terser-webpack-plugin/dist/minify.js:175:23) at module.exports (/Users/puser/Dropbox/AngularApps/GenesisFYI-v06/node_modules/terser-webpack-plugin/dist/worker.js:13:40) at handle (/Users/puser/Dropbox/AngularApps/GenesisFYI-v06/node_modules/worker-farm/lib/child/index.js:44:8) at process.<anonymous> (/Users/puser/Dropbox/AngularApps/GenesisFYI-v06/node_modules/worker-farm/lib/child/index.js:51:3) at process.emit (events.js:197:13) at emit (internal/child_process.js:828:12) at processTicksAndRejections (internal/process/next_tick.js:76:17)
My current Version
Angular CLI: 7.3.0 Node: 11.8.0 OS: darwin x64 Angular: 7.2.3 ... animations, common, compiler, compiler-cli, core, forms ... http, language-service, platform-browser ... platform-browser-dynamic, router, service-worker Package Version ----------------------------------------------------------- @angular-devkit/architect 0.13.0 @angular-devkit/build-angular 0.13.0 @angular-devkit/build-optimizer 0.13.0 @angular-devkit/build-webpack 0.13.0 @angular-devkit/core 0.6.8 @angular-devkit/schematics 0.6.8 @angular/cli 7.3.0 @angular/pwa 0.6.8 @ngtools/webpack 7.3.0 @schematics/angular 0.6.8 @schematics/update 0.13.0 rxjs 6.4.0 typescript 3.2.4 webpack 4.29.0
-
Mathias about 5 yearsNote: Running this works "ng build --prod --optimization=false"
-
Jakub Nurski about 5 yearsI've encountered the same issue like 20 minutes ago. The problem was that I had removed
package-lock.json
file. -
Mathias about 5 yearsThanks @Nuurek. Unfortunately, mine is there. And I did a npm Install just to try and rebuild it.
-
-
Mathias about 5 yearsThanks @pietro. I'll go look at that. I don't THINK I am setting the Terser version anywhere in my Angular config. I think that is pulled in from webpack. So let me go play.
-
Pietro Saccardi about 5 yearsWe had to pin it in
package.json
independencies
as follows:"terser": "^3.14.1"
. I think by default it pulls the latest version. -
Mathias about 5 yearsThank you @Pietro! That seems to have worked. I added "terser": "3.14.1" to my dependencies (no caret on mine), npm install, then the build with --prod worked.
-
John about 5 yearsI did not have "terser" in my package, but I added it to devDependencies, and it solved my problem. Maybe I was using some other npm module depending on terser.
-
Mathias almost 5 yearslooking at the message I would say this is a different issue. You probably should open your own separate question. By adding it here as an answer I believe few people will see it.
-
Mathias almost 5 yearsOr search for this - there look to be several answers - Terser Unexpected token: punc (:)
-
BozoJoe over 2 yearslikewise via angular.json -> configurations:production: "optimization": false,
-
Som over 2 yearsThank you boss! I almost spent a day to resolve it and did many things...but no luck . finally checked ("styles": [], "scripts": []) and resloved my issue.
-
Mario Luiz over 2 yearsI'm glad it helped you, at the time I wasted 3 days trying.