{"id":19072,"library":"babel-plugin-iife-wrap","title":"babel-plugin-iife-wrap","description":"A Babel plugin that wraps the entire file content in an Immediately Invoked Function Expression (IIFE) to avoid polluting the global scope. Current stable version 1.1.0 (latest, 2019). Simple and focused: no configuration options, works with Babel 7+. Differentiator: extremely minimal and does one thing—file-level IIFE wrapping, unlike more complex scope isolators.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/trysound/babel-plugin-iife-wrap","tags":["javascript","babel-plugin","iife","wrap"],"install":[{"cmd":"npm install babel-plugin-iife-wrap","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-iife-wrap","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-iife-wrap","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for Babel plugin interface.","package":"@babel/core","optional":true}],"imports":[{"note":"CommonJS-only module; no ESM export. Use require() in Node or Babel config.","wrong":"import iifeWrap from 'babel-plugin-iife-wrap';","symbol":"default","correct":"module.exports = require('babel-plugin-iife-wrap');"},{"note":"In Babel config, the plugin name can be shortened to 'iife-wrap' (without 'babel-plugin-' prefix).","wrong":"module.exports = { plugins: ['babel-plugin-iife-wrap'] };","symbol":"babel.config.js","correct":"module.exports = { plugins: ['iife-wrap'] };"},{"note":"Same shorthand works for CLI: omit 'babel-plugin-' prefix.","wrong":"babel --plugins babel-plugin-iife-wrap script.js","symbol":"Babel CLI","correct":"babel --plugins iife-wrap script.js"}],"quickstart":{"code":"// Install: npm i babel-plugin-iife-wrap --save-dev\n// Then add to babel.config.js:\nmodule.exports = {\n  plugins: ['iife-wrap']\n};\n// Input (input.js):\nvar x = 1;\nwindow.a = x;\n// Output:\n;(function () {\n  var x = 1;\n  window.a = x;\n}());","lang":"javascript","description":"Shows installation and basic usage: input file gets wrapped in IIFE to isolate variables from global scope."},"warnings":[{"fix":"Manually add semicolon or use a plugin like 'babel-plugin-add-import-extension' but note that this plugin does not add prefix ';'.","message":"Plugin does not add semicolon before IIFE; output may break if previous file lacks semicolon. Always ensure semicolons or use a separate tool.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Do not use with ES module syntax (import/export). For modules, consider different scoping techniques.","message":"Only wraps the entire file; does not handle modules or imports. If used with ES modules, output may be invalid JavaScript.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"No workaround; choose another plugin if customization is needed.","message":"No configuration options—cannot customize IIFE parameters or use strict mode. The plugin always wraps in an anonymous function with no arguments.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run: npm install babel-plugin-iife-wrap --save-dev. Then in .babelrc: { \"plugins\": [\"iife-wrap\"] }","cause":"Plugin not installed or not listed in .babelrc plugins array correctly.","error":"Error: Could not find plugin 'babel-plugin-iife-wrap'"},{"fix":"Ensure @babel/core version 7+ is installed as peer dependency.","cause":"Potential compatibility issue with older Babel versions (likely <7).","error":"TypeError: this.cache is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}