{"id":19191,"library":"babel-plugin-transform-es2015-block-scoped-functions","title":"babel-plugin-transform-es2015-block-scoped-functions","description":"Babel plugin (v6.22.0) that transforms function declarations inside blocks to be block-scoped, ensuring compatibility with ES2015 semantics in older environments. This plugin is part of Babel's deprecated 'es2015' preset and is no longer maintained independently. It converts block-level function declarations to variable assignments with the same name, preventing hoisting issues. For modern Babel usage (v7+), use @babel/plugin-transform-block-scoped-functions instead.","status":"deprecated","version":"6.22.0","language":"javascript","source_language":"en","source_url":"https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-block-scoped-functions","tags":["javascript","babel-plugin"],"install":[{"cmd":"npm install babel-plugin-transform-es2015-block-scoped-functions","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-transform-es2015-block-scoped-functions","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-transform-es2015-block-scoped-functions","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Requires babel-core to run as a plugin","package":"babel-core","optional":false}],"imports":[{"note":"Used in .babelrc or babel.config.js plugin array","symbol":"plugin (default)","correct":"{\n  \"plugins\": [\"transform-es2015-block-scoped-functions\"]\n}"},{"note":"This old plugin is CJS-only; cannot use ESM import syntax in older Babel versions","wrong":"import { transform } from 'babel-core'; transform(code, { plugins: ['transform-es2015-block-scoped-functions'] })","symbol":"plugin (programmatic)","correct":"require('babel-core').transform(code, { plugins: ['transform-es2015-block-scoped-functions'] })"},{"note":"Package does not provide ESM exports; use require only","wrong":"import plugin from 'babel-plugin-transform-es2015-block-scoped-functions';","symbol":"require('babel-plugin-transform-es2015-block-scoped-functions')","correct":"const plugin = require('babel-plugin-transform-es2015-block-scoped-functions');"}],"quickstart":{"code":"// .babelrc\n{\n  \"plugins\": [\"transform-es2015-block-scoped-functions\"]\n}\n\n// Input\nfunction f() { return 1; }\n{\n  function f() { return 2; }\n}\nf(); // now returns 1 instead of 2 in older engines\n\n// Output (transformed)\nfunction f() { return 1; }\n{\n  var _f = function f() { return 2; };\n}\nf(); // returns 1\n\n// Via Node API\nvar babel = require('babel-core');\nvar result = babel.transform('{ function foo() {} }', {\n  plugins: ['transform-es2015-block-scoped-functions']\n});\nconsole.log(result.code);","lang":"javascript","description":"Shows how to configure and use the plugin to block-scope function declarations within blocks."},"warnings":[{"fix":"Replace with @babel/plugin-transform-block-scoped-functions in Babel v7 projects.","message":"This package is deprecated as of Babel v7. Use @babel/plugin-transform-block-scoped-functions instead.","severity":"deprecated","affected_versions":">=6.0.0"},{"fix":"Use @babel/plugin-transform-block-scoped-functions or include in @babel/preset-env (which automatically includes it when needed).","message":"Plugin renaming: babel-plugin-transform-es2015-block-scoped-functions has been renamed to @babel/plugin-transform-block-scoped-functions in Babel v7.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Upgrade to @babel/core v7 and use @babel/plugin-transform-block-scoped-functions.","message":"Does not work with Babel v7 or later; only compatible with babel-core v6.","severity":"gotcha","affected_versions":">=7.0.0"},{"fix":"No fix needed; understand the scope of the plugin.","message":"Plugin only applies to function declarations at block level; does not affect arrow functions or function expressions.","severity":"gotcha","affected_versions":">=6.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"npm install babel-plugin-transform-es2015-block-scoped-functions --save-dev (for Babel 6) or use @babel/plugin-transform-block-scoped-functions (for Babel 7+)","cause":"Package not installed or using wrong Babel version.","error":"Error: Cannot find module 'babel-plugin-transform-es2015-block-scoped-functions'"},{"fix":"Switch to @babel/plugin-transform-block-scoped-functions.","cause":"Using the plugin with Babel v7 which expects @babel/plugin prefix.","error":"Plugin/Preset files are not allowed to export objects, only functions"},{"fix":"Ensure plugin name is correct and in quotes: \"transform-es2015-block-scoped-functions\"","cause":"Typo or wrong configuration format.","error":"Error: Invalid plugin \"transform-es2015-block-scoped-functions\" specified in"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}