Registry / devops / infinite-loop-loader

infinite-loop-loader

JSON →
library1.0.9jsnpmunverified

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.

npm install infinite-loop-loader
INSTALL
IMPORT
SIG · INFINITE-LOOP-LOAD
I
infinite-loop-loader
devopsjavascriptv1.0.9
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Webpack configuration to transform infinite loops in all JS files with a limit of 100000 iterations.

// webpack.config.js module.exports = { module: { rules: [ { test: /\.js$/, use: { loader: 'infinite-loop-loader', options: { limit: 100000, opts: { allowImportExportEverywhere: true, }, }, }, }, ], }, };
Debug
Known issues
gotchaThe 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.
affects: *
gotchaThe 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.
affects: *
gotchaThe 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.
affects: *
breakingMinimum 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.
affects: >=5.0
deprecatedThe 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.
affects: *
Errors
Common errors & fixes
Module build failed: Error: 'infinite-loop-loader' is not a valid loader
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: custom iteratee is not supported
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.
TypeError: Cannot read properties of undefined (reading 'start')
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.
Upgrade
Version history
1.0.9latest on npm
Audit
Dependencies
falafelrequiredAST traversal and transformation of JavaScript code
acornrequiredJavaScript parser used by falafel
loader-utilsrequiredWebpack loader utility to parse options
Agent activity
4 hits · last 30 days
node
4
Resources
infinite-loop-loader — npm install infinite-loop-loader · libregistry