{"id":12726,"library":"es6-shim","title":"ES6 Shim","description":"The `es6-shim` package provides compatibility shims to enable ECMAScript 6 (Harmony) features in legacy JavaScript environments that lack native support. This includes core language features like `Promise`, `Map`, and `Set`, as well as numerous methods on `String`, `Number`, and `Array` prototypes such as `String.prototype.includes` or `Number.isInteger`. It operates by patching the global scope, making these features available as if they were natively implemented. The current stable version is 0.35.8, which primarily focuses on bug fixes, robustness improvements, and spec compliance. As a polyfill library, its release cadence is driven by bug reports and updates to the ECMAScript specification, rather than frequent feature additions, differentiating it from libraries introducing new paradigms. It aims to make older engines behave as closely as possible to the ES6 standard.","status":"maintenance","version":"0.35.8","language":"javascript","source_language":"en","source_url":"git://github.com/paulmillr/es6-shim","tags":["javascript","ecmascript","harmony","es6","shim","promise","promises","setPrototypeOf","map"],"install":[{"cmd":"npm install es6-shim","lang":"bash","label":"npm"},{"cmd":"yarn add es6-shim","lang":"bash","label":"yarn"},{"cmd":"pnpm add es6-shim","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required to correct broken ES5 implementations and should be loaded before `es6-shim` for comprehensive polyfilling. Some ES6 features (like Map/Set) rely on ES5 property descriptor support.","package":"es5-shim","optional":false},{"reason":"Optional dependency required only if `String.prototype.normalize` support is needed, as it provides the underlying Unicode normalization algorithm.","package":"unorm","optional":true}],"imports":[{"note":"Includes all ES6 shims and polyfills into the global scope. Ensure `es5-shim.js` is loaded before this script if needed, typically from `node_modules/es5-shim/es5-shim.js`.","wrong":"<script src=\"es6-shim.js\"></script> (if not copied to root), or not loading es5-shim first","symbol":"Global ES6 Polyfills (Browser)","correct":"<script src=\"node_modules/es6-shim/es6-shim.js\"></script>"},{"note":"Loads all ES6 shims and polyfills into the global Node.js environment. It is strongly recommended to also `require('es5-shim');` *before* this line for robust polyfilling across various environments.","wrong":"import 'es6-shim'; (Incorrect ES module syntax for this package)","symbol":"Global ES6 Polyfills (Node.js/CommonJS)","correct":"require('es6-shim');"},{"note":"The `es6-sham` file provides shims for features that are not fully compliant with the ES6 spec or have known side effects (e.g., `Function.prototype.name`). Load it explicitly if these specific shims are desired.","wrong":"require('es6-shim'); (This only loads the main shim, not the 'sham')","symbol":"ES6 Sham (Node.js/CommonJS)","correct":"require('es6-shim/es6-sham');"}],"quickstart":{"code":"// In a browser environment, you would include these via script tags in your HTML:\n// <script src=\"node_modules/es5-shim/es5-shim.js\"></script>\n// <script src=\"node_modules/es6-shim/es6-shim.js\"></script>\n\n// For Node.js or a bundler:\nrequire('es5-shim'); // Recommended for comprehensive polyfilling\nrequire('es6-shim');\n\n// Now, ES6 features are available globally\nconsole.log('--- Map Example ---');\nconst myMap = new Map();\nmyMap.set('key1', 'value1');\nmyMap.set('key2', 'value2');\nconsole.log('Map size:', myMap.size); \nconsole.log('Has key1:', myMap.has('key1')); \n\nconsole.log('\\n--- Promise Example ---');\nnew Promise((resolve) => {\n  setTimeout(() => resolve('Promise resolved!'), 100);\n}).then(message => {\n  console.log(message); \n}).catch(error => {\n  console.error('Promise rejected:', error);\n});\n\nconsole.log('\\n--- String.prototype.includes Example ---');\nconst greeting = 'Hello world!';\nconsole.log('\"world\" included:', greeting.includes('world')); \nconsole.log('\"foo\" included:', greeting.includes('foo'));     \n\nconsole.log('\\n--- Number.isInteger Example ---');\nconsole.log('Is 42 an integer:', Number.isInteger(42));     \nconsole.log('Is 3.14 an integer:', Number.isInteger(3.14)); \n","lang":"javascript","description":"Demonstrates how to include `es6-shim` and `es5-shim` and then use various ECMAScript 6 features like `Map`, `Promise`, `String.prototype.includes`, and `Number.isInteger` that are polyfilled by the library."},"warnings":[{"fix":"Refactor any code relying on `Reflect.enumerate` to use alternative introspection methods, or if absolutely necessary, stick to an `es6-shim` version prior to 0.35.0. However, relying on a removed spec feature is not recommended.","message":"The `Reflect.enumerate` shim was removed from `es6-shim` in version 0.35.0, aligning with its removal from the official ECMAScript specification.","severity":"breaking","affected_versions":">=0.35.0"},{"fix":"In browsers, ensure `<script src=\"es5-shim.js\">` appears before `<script src=\"es6-shim.js\">`. In CommonJS, `require('es5-shim');` must precede `require('es6-shim');`.","message":"For comprehensive and correct polyfilling, `es5-shim` must always be loaded *before* `es6-shim`. Some ES6 features (like `Map` and `Set`) rely on correct ES5 property descriptor behavior, which `es5-shim` corrects in older environments.","severity":"gotcha","affected_versions":"all"},{"fix":"Always include `es5-shim` alongside `es6-shim`, as `es5-shim` provides the necessary polyfills for ES5 property descriptor support in older environments.","message":"The `Map` and `Set` shims, among others, require the target JavaScript environment to have support for ES5 property descriptors. Without this, these shims may not function correctly or at all.","severity":"gotcha","affected_versions":"all"},{"fix":"If `String.prototype.normalize` is needed, install `unorm` (`npm install unorm`) and ensure it's loaded alongside `es6-shim` (e.g., `require('unorm');`).","message":"The `String.prototype.normalize` shim is incomplete by itself and requires the separate `unorm` package to provide the underlying Unicode normalization algorithm.","severity":"gotcha","affected_versions":"all"},{"fix":"If you require shims for features covered by `es6-sham.js`, you must explicitly include it (e.g., `require('es6-shim/es6-sham');`) *after* `es6-shim.js`.","message":"The `es6-shim` package provides two main files: `es6-shim.js` (for generally safe shims) and `es6-sham.js` (for shims that are less compliant or have potential side effects, such as `Function.prototype.name`).","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure `es5-shim` and `es6-shim` are correctly loaded in the specified order before attempting to use ES6 features. Verify that the browser/environment meets the minimum requirements for the shims to function.","cause":"The `es6-shim` was not loaded, or `es5-shim` (a prerequisite for some features) was not loaded, or the browser/environment is too old even for shims.","error":"TypeError: 'Map' is not a constructor (or similar for Set, Promise)"},{"fix":"Update `es6-shim` to version 0.34.3 or higher, which includes fixes for these issues. Additionally, ensure all promises have a `.catch()` handler to explicitly manage rejections and prevent unhandled promise rejections.","cause":"Older Chrome versions (pre-50) or certain environments might incorrectly handle promise rejections, particularly with non-Error objects, leading to console warnings or errors.","error":"Uncaught (in promise) TypeError: A promise was rejected with a non-error object. (or similar 'uncaught rejection' console warnings)"},{"fix":"Verify that the `es6-shim` script is included in your HTML before your application code, or that `require('es6-shim')` is called at the very top of your application's entry point or module where these features are first used.","cause":"The `es6-shim` was not loaded at all, or not loaded early enough in the execution flow before these global objects were accessed.","error":"ReferenceError: Promise is not defined (or Map, Set, etc. is not defined)"},{"fix":"For environments that do not support modern JavaScript syntax, you must use a transpiler like Babel to convert ES6+ syntax to ES5-compatible code. `es6-shim` only provides runtime polyfills for built-in objects and methods.","cause":"`es6-shim` polyfills ECMAScript 6 *features* (e.g., `Map`, `Promise`), but it does not transpile ECMAScript 6+ *syntax* (`const`, `let`, arrow functions, classes) for older JavaScript engines.","error":"SyntaxError: 'const' is a reserved word (or similar for `let`, arrow functions)"}],"ecosystem":"npm"}