{"id":10988,"library":"gulp-javascript-obfuscator","title":"Gulp JavaScript Obfuscator","description":"gulp-javascript-obfuscator is a Gulp plugin that integrates the powerful `javascript-obfuscator` library into Gulp build workflows. Currently at version 1.1.6, this package provides a stream-based interface for obfuscating JavaScript files, adding a layer of protection against reverse engineering and making code harder to read. This plugin is typically stable, with its release cadence tied to updates in the underlying `javascript-obfuscator` for feature enhancements and Gulp-specific maintenance. A key differentiator is its seamless integration with `gulp-sourcemaps`, which allows for proper debugging of obfuscated code by automatically generating corresponding source maps. This ensures a robust and maintainable obfuscation process within existing Gulp pipelines and supports chaining with other Gulp plugins like Babel for pre-processing.","status":"maintenance","version":"1.1.6","language":"javascript","source_language":"en","source_url":"https://github.com/javascript-obfuscator/gulp-javascript-obfuscator","tags":["javascript","gulpplugin","obfuscate","obfuscation","javascript-obfuscator","obfuscator","protect","conceal"],"install":[{"cmd":"npm install gulp-javascript-obfuscator","lang":"bash","label":"npm"},{"cmd":"yarn add gulp-javascript-obfuscator","lang":"bash","label":"yarn"},{"cmd":"pnpm add gulp-javascript-obfuscator","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for performing the actual JavaScript obfuscation. This plugin is a wrapper around it.","package":"javascript-obfuscator","optional":false},{"reason":"Highly recommended for generating source maps, which is essential for debugging obfuscated code. It handles sourcemap generation for the obfuscated output.","package":"gulp-sourcemaps","optional":true},{"reason":"Peer dependency for any Gulp plugin to function within a Gulp build system.","package":"gulp","optional":false}],"imports":[{"note":"This is a CommonJS module, primarily used in Gulpfiles which are typically CommonJS. Direct ESM `import` will not work.","wrong":"import javascriptObfuscator from 'gulp-javascript-obfuscator';","symbol":"javascriptObfuscator","correct":"const javascriptObfuscator = require('gulp-javascript-obfuscator');"},{"note":"Gulpfiles are traditionally CommonJS modules. `import` syntax is not typically supported without additional transpilation.","wrong":"import gulp from 'gulp';","symbol":"gulp","correct":"const gulp = require('gulp');"},{"note":"Like other Gulp plugins, `gulp-sourcemaps` is imported using CommonJS `require` in a Gulpfile.","wrong":"import sourcemaps from 'gulp-sourcemaps';","symbol":"sourcemaps","correct":"const sourcemaps = require('gulp-sourcemaps');"}],"quickstart":{"code":"const gulp = require('gulp');\nconst javascriptObfuscator = require('gulp-javascript-obfuscator');\nconst sourcemaps = require('gulp-sourcemaps');\nconst babel = require('@babel/core'); // Optional: for pre-processing JS\nconst babelPresetEnv = require('@babel/preset-env'); // Optional: for Babel preset\n\ngulp.task('obfuscate-js', () => {\n  return gulp.src('src/**/*.js')\n    .pipe(sourcemaps.init()) // Initialize sourcemaps before any transformations\n    .pipe(babel({\n      presets: [babelPresetEnv]\n    })) // Optional: Transpile modern JS to a compatible version\n    .pipe(javascriptObfuscator({\n      compact: true, // Example option: compact the obfuscated code\n      // Other javascript-obfuscator options can go here\n      // IMPORTANT: Do NOT set `sourceMap: true` here when using gulp-sourcemaps\n    }))\n    .pipe(sourcemaps.write('.')) // Write sourcemaps to the same directory as output\n    .pipe(gulp.dest('dist')); // Output obfuscated and sourcemap files to 'dist'\n});\n\n// To run this task: npx gulp obfuscate-js","lang":"javascript","description":"This quickstart demonstrates how to set up a Gulp task to obfuscate JavaScript files, incorporating Babel for transpilation and `gulp-sourcemaps` for generating debug-friendly sourcemaps alongside the obfuscated output."},"warnings":[{"fix":"Remove `sourceMap` from the options object passed to `javascriptObfuscator()`. Ensure `sourcemaps.init()` is called before and `sourcemaps.write()` after the obfuscator in the Gulp pipeline.","message":"When using `gulp-sourcemaps` for source map generation, the `sourceMap` option within `javascript-obfuscator` configurations MUST NOT be set. The plugin handles source map integration automatically, and explicitly setting `sourceMap: true` will cause conflicts or incorrect behavior.","severity":"breaking","affected_versions":">=1.1.6"},{"fix":"Migrate to using `gulp-sourcemaps` for robust and compatible source map generation. Follow the `gulp-sourcemaps` integration pattern: `pipe(sourcemaps.init()).pipe(javascriptObfuscator()).pipe(sourcemaps.write())`.","message":"The method of generating source maps by directly setting `sourceMap: true` in the `javascript-obfuscator` options (without `gulp-sourcemaps`) is deprecated. This older approach generates a `.map` file directly into the Gulp stream but is not recommended for future use and may be removed in later versions.","severity":"deprecated","affected_versions":">=1.1.6"},{"fix":"If encountering these errors, consider downgrading to a compatible Node.js LTS version (e.g., Node.js 12.x) or updating `gulp-javascript-obfuscator` and its core dependency `javascript-obfuscator` to their latest versions if a fix has been released for your Node.js version.","message":"Older Node.js versions (e.g., 13.6 and above) have been reported to cause 'Spread Syntax error' or 'The number of constructor arguments in the derived class must be >= than the number of constructor arguments of its base class' when using `gulp-javascript-obfuscator` due to incompatibilities with underlying dependencies.","severity":"gotcha","affected_versions":"<=1.1.6 (specific Node.js 13.x versions)"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Downgrade your Node.js version to a compatible LTS release (e.g., Node.js 12.x) or check for newer versions of `gulp-javascript-obfuscator` and `javascript-obfuscator` that support your Node.js version.","cause":"Incompatibility between `javascript-obfuscator`'s internal dependencies and specific Node.js versions (e.g., Node.js 13.6+).","error":"Error in plugin \"gulp-javascript-obfuscator\" Message: The number of constructor arguments in the derived class t must be >= than the number of constructor arguments of its base class."},{"fix":"Ensure your Node.js version supports the syntax used by the library and its dependencies, or use a transpiler like Babel if targeting older environments. Check `javascript-obfuscator`'s compatibility matrix.","cause":"Older Node.js environments or misconfigured transpilation pipelines struggling with modern JavaScript syntax used by `javascript-obfuscator` or its sub-dependencies.","error":"SyntaxError: Unexpected token ... (related to spread syntax in `chalk` or other dependencies)"},{"fix":"Verify that `const javascriptObfuscator = require('gulp-javascript-obfuscator');` is correctly placed and that `javascriptObfuscator` is used as a function in the `.pipe()` chain.","cause":"The `gulp-javascript-obfuscator` module was not correctly `require`d, or the variable name does not match the imported symbol.","error":"TypeError: javascriptObfuscator is not a function"},{"fix":"Run `npm install` or `yarn install` again to ensure all transitive dependencies are correctly installed. This can sometimes be resolved by clearing the npm cache (`npm cache clean --force`).","cause":"A dependency issue where `gulp-sourcemaps` or `gulp-javascript-obfuscator` cannot find a required sub-dependency for sourcemap processing.","error":"Error: Cannot find module 'vinyl-sourcemaps-apply'"}],"ecosystem":"npm"}