infinite-loop-loader
raw JSON → 1.0.9 verified Sat Apr 25 auth: no javascript
A webpack loader that transforms infinite loops (e.g., `while(true)`) by injecting an iteration counter and a throw statement when the limit is exceeded. Version 1.0.9 is the latest stable release. It is part of the OpenComponents ecosystem but can be used standalone. The loader uses falafel/acorn to parse and transform JavaScript. Unlike manual linting or AST-based approaches, this provides a runtime safeguard for accidental infinite loops in webpack-bundled code. It supports configuration of the iteration limit and Acorn parser options. The package ships TypeScript definitions.
Common errors
error Module build failed: Error: 'infinite-loop-loader' is not a valid loader ↓
cause The loader is not installed or webpack cannot resolve it.
fix
Run
npm install --save-dev infinite-loop-loader and check that node_modules contains the package. error Error: custom iteratee is not supported ↓
cause Falafel's iteratee function is not compatible with the version used by this loader, or the Acorn options are invalid.
fix
Update to the latest version of infinite-loop-loader and ensure the
opts object contains valid Acorn parser options. error TypeError: Cannot read properties of undefined (reading 'start') ↓
cause The loader received a malformed source or an empty file. This can happen if the file is not valid JavaScript or if the test pattern matches non-JS files.
fix
Ensure the
test regex only matches .js files and that the files contain valid JavaScript syntax. Warnings
gotcha The loader only transforms while(true) and while(1) patterns. Other infinite loop constructs (e.g., for(;;) or do{}while(true)) are not transformed. ↓
fix Manually refactor other loop styles to while(true) if you need them to be guarded.
gotcha The injected counter variable name (__ITER) can conflict with user-declared variables. The loader does not perform scope analysis. ↓
fix Avoid using the identifier __ITER in your source code, or rename it if possible.
gotcha The default iteration limit is 1000000000, which is extremely high and may not catch unintended infinite loops in a timely manner. ↓
fix Set a sensible limit via the `limit` option in the loader configuration.
breaking Minimum webpack version required is 2. May not work with webpack 5 due to changes in loader API. ↓
fix Upgrade to a maintained alternative or check compatibility with webpack 5.
deprecated The package relies on falafel, which is no longer actively maintained. Acorn options are passed through falafel, which may cause issues with newer Acorn versions. ↓
fix Consider using a more modern AST-based tool or babel plugin.
Install
npm install infinite-loop-loader yarn add infinite-loop-loader pnpm add infinite-loop-loader Quickstart
// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.js$/,
use: {
loader: 'infinite-loop-loader',
options: {
limit: 100000,
opts: {
allowImportExportEverywhere: true,
},
},
},
},
],
},
};