Questions tagged [terser]

Terser is a JavaScript parser and mangler/compressor toolkit for ES6+ (ECMAScript 6+ / JavaScript 6+)

Filter by
Sorted by
Tagged with
0 votes
0 answers
11 views

Rollup terser doesn't mangle correctly with modules

I have got 2 files which should be connected with imports and exports, but the problem is that the rollup-plugin-terser mangles imports from the second file not correctly, it trying to call methods of ...
0 votes
0 answers
24 views

Remove comments and console.log in webpack with Terser

In my web project i use webpack 5 with Terser. I want to remove all comments and console.log but it doesn't work. This are my webpack settings and i found this in the documentation of terser: ...
  • 237
0 votes
2 answers
254 views

vite: use "keep-names" esbuild flag for production build

one of our third party libraries requires us to preserve specific function names. in webpack we did that with terser.keep_fnames. esbuild has https://esbuild.github.io/api/#keep-names so we'd like to ...
0 votes
0 answers
34 views

ERROR in bundle.js from Terser Invalid assignment bundle.js

I have a problem with terser-webpack-plugin I can't minify my bundle the error is ERROR in bundle.js from Terser Invalid assignment bundle.js I have the version of "terser-webpack-plugin": &...
0 votes
0 answers
163 views

Sourcemap is likely to be incorrect: a plugin (terser) was used to transform files, but didn't generate a sourcemap for the transformation

I'm trying to upgrade mui, rollup, nodejs and npm but encountered this errorenter image description here tsconfig all packages are in their latest version tried these: Rollup is not generating ...
0 votes
1 answer
55 views

Problems with VS Code JavaScript Intellisense and ES6 Import with Minified & Non-minified Version of JS

Below is my Firebase hosting project folder structure: projectFolder/store/public/scripts/*.min.js projectFolder/src/*.js After running terser, all my projectFolder/src/*.js will be minified to ...
  • 1,471
0 votes
0 answers
81 views

Eleventy / Nunjucks: minify JS with terser within minified HTML

I try to minify partial HTML in which I minify some JS using terser (using a jsmin filter as showed in 11ty docs): <!doctype html> <html lang="fr"><head><meta charset=&...
  • 629
0 votes
0 answers
555 views

Webpack build results Terser Error: Unexpected token: punc ())

I've been cleaning up my npm audit errors and after I was done I could not execute npm tun build anymore. Error ERROR in web/themes/custom/js/funds-chunk.js from Terser Unexpected token: punc ()) [...
0 votes
0 answers
31 views

tls-browserify preventing Next build from running

Whenever I try to run next build it's failing due to webpack errors which from the stack trace is being thrown is coming from the tls-browserify (which my application depends on) library due to it ...
0 votes
1 answer
383 views

Vite: This module can only be imported inside a service worker

After a pnpm package update, I can't start my SvelteKit project anymore. Something is messy with the tooling: pnpm, vite, sass, terser or sveltekit, I don't know. > pnpm run dev VITE v4.0.0 ready ...
0 votes
0 answers
82 views

React-Native JSX code to minify using terser

I am using terser to minify React-native code but I cannot seem to find the appropriate options needed to minify React-native code and so I am getting the error "Unexpected token operator (<)&...
0 votes
0 answers
9 views

How to set the target ECMAscript version of Babel/Webpack in an ejected CRA React app?

I want to use Terser's webpack plugin to uglify (mangle property names) in my project. The problem is webpack/babel is fixated on transpiling getter/setter properties to a syntax that I assume is ...
0 votes
0 answers
59 views

dead code elimination for unused class methods

Let's say I have these class methods export class App { get not_used_either() { return 'really long string' } not_used() { console.log('really long string') } } When minifying using ...
  • 5,984
0 votes
1 answer
111 views

How to mangle function names used in event attributes with html-minifier-terser?

I am using the latest https://github.com/terser/html-minifier-terser 7.0.0 (https://www.npmjs.com/package/html-minifier-terser) The readme states Minify JavaScript in script elements and event ...
  • 5,719
0 votes
0 answers
64 views

Change JavaScript output before terser kicks in in Angular

Is it possible in an Angular 13 project to change the content in the generated main.js file before it is given to the minifier/optimizer/obfuscator (in Angular, it is terser)? A very exotic ...
  • 2,754
0 votes
0 answers
83 views

How to avoid duplicate licenses with Parcel?

Is there a way to extract or duplicate the licenses when using Parcel (or Terser at it seems to be the underlying minifier)? The terser webpack plugin seems have a custom option extractComments https:/...
  • 1,205
1 vote
1 answer
264 views

Terser: Only mangle matched property names from regex

I want to keep ALL my variables and function names, even the private ones, and only mangles the ones that match the regex. The docs say: regex (default: null) — Pass a RegExp literal or pattern ...
  • 668
1 vote
0 answers
111 views

Grunt-terser failing to minify React JSX code on Sails

I am using browserify with babelify to transpile React code from ES6 and everything went smoothly until trying to minify using Uglify and discovered that Uglify doesn't do ES6 syntax, so I switched to ...
  • 11
0 votes
0 answers
192 views

Error: Optimization error TypeError: Cannot read properties of undefined (reading 'comments_before') Angular 13

i am using angular 13.3.9 When i run angular ng build , i encounter with error on build time, it seems the error happens in terser package , but the ng serve works fine , here is the full error coded ...
  • 51
0 votes
1 answer
199 views

Vue 2: Minify JS files using Terser

I want to compress my js files using Terser Plugin. Here is my dependencies "dependencies": { "axios": "^0.26.0", "core-js": "^3.6.5", &...
  • 77
0 votes
0 answers
138 views

Terser setting to minify/hoist the this variable and properties

Is there any way for terser to minify/hoist the this variable so it does not appear repeated as often in the bundle? Example code: class MyClass { constructor(handler) { this.handler = ...
  • 5,748
2 votes
0 answers
716 views

webpack/terser: How can I exclude a package from minification, but still include that package in the packed result?

I've found a number of solutions for excluding particular modules from minification, but all of the solutions I've seen so far not only skip minification of those packages, they cause those packages ...
  • 12.1k
0 votes
1 answer
59 views

Minify calls to Math, Number, etc. with Terser

The code that Terser produces for my project contains many calls to the Javascript Math object and I am wondering if there is an easy way to minify these calls. Here is a screenshot of part of the ...
  • 3,163
0 votes
0 answers
191 views

Error: Cannot find module .../node_modules/terser-webpack-plugin/dist/index.js'. Please verify that the package.json has a valid "main" entry - REACT

I think this is worth to ask here. I created an app with npx-create-react-app@latest and then when I wanted to run npm start, I got this error: node:internal/modules/cjs/loader:361 throw err; ...
0 votes
1 answer
1k views

Cannot find module terser-webpack-plugin when run yarn serve in Vue 3 project

I just created a Vue 3 project using Vue CLI using the default options, and when I try to run using yarn serve command I got this error Error: Cannot find module '.../node_modules/terser-webpack-...
0 votes
1 answer
997 views

Minify JS with VS code extension

I need: minify JS file with extension from the store, but I can't find an option to remove whitespace between html tags in variables I use: JS & CSS Minifier (Minify) - https://marketplace....
  • 145
0 votes
0 answers
132 views

Terser eror Unexpected token: punc (}) [.js/1.chunk.js:3596,78] at ee (C:\..) in webpack when creating a react typescript productin build with aws-sdk

I'm trying to integrate cognito-identity-js and aws-sdk in my react typescript project. While I'm using aws-sdk module and trying to create build, I'm getting the following error ERROR in .js/1....
0 votes
0 answers
18 views

minify heroku slugs on build terser

I recently used "heroku run" and looked around inside my package.json nodejs app, the slug is NOT minified in /node_modules . I am using the standard "heroku/nodejs" buildpack. ...
  • 31
0 votes
0 answers
164 views

How to remove console.log of dependency modules using Rollup, Except my codes

I want to remove console.log of dependency modules (node_modules). So I tried terser({ compress: { drop_console: true } }). But, It drops even console.log of my codes. I want to remove console.log of ...
2 votes
1 answer
189 views

Terser: Annotate function as always pure (and what does it mean)

To assist with optimization Terser supports the pure comment to indicate that a function call is pure. Specifically, the docs give only the following example. const x = /*#__PURE__*/...
  • 2,018
0 votes
0 answers
329 views

Webpack optimization | Terser plugin not reflecting any change in bundle size

I am using Terser plugin to minify the bundle size in production mode, but I am not able to see any change in bundle size. Is this because Terser plugin is automatically applied in production mode? I ...
  • 1,898
4 votes
1 answer
876 views

Typescript const enum alternative

More and more modern Typescript transpilers have moved toward a strategy of per-module transpilation, which significantly increases build speed, but eliminates the possibility for cross-module const ...
  • 7,087
0 votes
0 answers
196 views

How to debug terser mangle properties keep quoted true rendering webgl of black screen

I have this terser plugin in rollup: const { terser } = require('rollup-plugin-terser') plugins = [terser()] if I pass this options: plugins = [terser({ mangle: { properties: { keep_quoted: true } } ...
  • 5,984
3 votes
1 answer
739 views

How to resolve "Parcel build failed. @parcel/optimizer-terser: "_" is redeclared" error

Good day everyone! When I tried to build my parcel-based app, I encountered the following error: Build failed. @parcel/optimizer-terser: "_" is redeclared 3724 | > 3725 | let _ = (t1)=...
1 vote
1 answer
1k views

My Razzle Terser build is broken ''Unexpected token: punc (.)'

I have a Razzle app and build is broken. It doesn't make sense as the error shown in build result points to something that doesn't exist in my code. This is the error message from Terser: 'Unexpected ...
4 votes
0 answers
729 views

Minifying a CSS file using terser

I have had some success minifying a .js file using terser. However, I have so far not been able to minify a standalone CSS file, and this is the reason for this qestion. I have installed html-minifier-...
  • 610
2 votes
2 answers
608 views

Terser keep (don't mangle) a specific function name

Is there a way to not mangle only one function name? A comment in the code would be easiest, but I guess this could be done by specifying a custom "nameCache" ? But I don't know how that ...
  • 1,040
2 votes
0 answers
101 views

Tree-shaking development builds with webpack

I have a dependency that includes references to document that gets imported into a service worker. The documents are tree-shaken out in production mode. However, I actually need for my service worker ...
1 vote
0 answers
98 views

Webpack: Modify source before generating source maps

I'm using Webpack 4, SourceMapDevToolPlugin and terser-webpack-plugin. The problem is that I need to also modify the minified JS-bundles – inject specific code to the beginning of file. The mutation ...
1 vote
0 answers
369 views

Webpack @azure/storage-blob node-fetch AbortSignal issue

I am facing one particular issue often talked about at various places the link I will share later. The problem is related to the webpack bundling. My nodeJS application uses @azure/storage-blob ...
  • 728
0 votes
1 answer
138 views

ng build --prod error after removing the bootstrap

I am using angular11 and after removing the bootstrap from my project it gives below error when run command ng build --prod Earlier it is working fine. i tried to update core and terser depenadicies ...
  • 66
1 vote
1 answer
388 views

How do I register a compressor with sprockets on the command line?

I want to use Sprockets at the command line (with the ruby-sprockets Debian package), and I want to use Terser as the JavaScript compressor (because Uglify doesn't support ES6). All the documentation ...
3 votes
0 answers
659 views

Keep some comments in Webpack 5 production javascript output

I think I'm going insane, because every search engine throws me only results on how to remove the comments from output file and that's completely opposite of what I searched for 😤 I use all defaults ...
  • 858
3 votes
1 answer
624 views

Terser: prefix all mangled variables and functions

I'm working on a single-file script that is meant to be included on pages through a <script> tag, it's being built with Vite.js using the Terser minifier. After making changes I noticed that the ...
  • 1,160
1 vote
0 answers
175 views

How to retrieve the nameCache from minify-html minifyJs (UglifyJS / Terser) after a Gulp task stream pipeline

I am using the Terser fork of UglifyJS inside the Gulp wrapper of html-minify and want to persist and restore the minifyJS nameCache. The underlying Terser library explains how to do it here but that ...
  • 6,489
0 votes
2 answers
1k views

Laravel mix, webpack, terser - strip console log in production bundle

I'm trying to strip console log and console debugs from the production build of my laravel + react app. I found many different solutions but none seemed suitable for my environment. I'm still trying ...
  • 43
0 votes
1 answer
239 views

ERROR while ng build --prod "Cannot negate a statement"

I am using following command to build angular project (it has some bower components under assets folder): ./node_modules/.bin/ng build --prod --base-href /project And after running above command I ...
1 vote
0 answers
254 views

How to investigate vague "js/chunk-venders... from Terser" undefined failure?

My Vue-CLI project is failing to create a production build: ⠏ Building for production... ERROR Failed to compile with 1 errors ...
0 votes
1 answer
484 views

dotenv-webpack and terser: error from Terser Invalid assignment

I'm working on an electron application. I've added the dotenv-webpack plugin in webpack config, but when I try to build it, I receive an error from Terser. Furthermore, if I comment on the ...
1 vote
1 answer
1k views

How do I get sourcemaps my original TypeScript code using rollup and terser?

A similar question was asked here: Rollup is not generating typescript sourcemap ..but about rollup with svelte for minification (with which I'm not familiar) rather than terser. I'm not sure how much ...
  • 12.1k