Registry / devops / redis-lua2js

redis-lua2js

JSON →
library6.0.0jsnpmunverified

Converts a Redis Lua script into a Node.js module string (CommonJS or ESM) that exports the script's name, key count, and Lua source. Version 6.0.0 supports both CJS and ESM output types. It is a build-time tool meant to integrate with Gulp or hook-based loaders, not for direct runtime use. Compared to alternatives like manually loading Lua files, it automates extracting metadata from Lua comments and provides a standard interface compatible with ioredis. Release cadence is low; last major version dropped support for older Node.js (requires >=20).

npm install redis-lua2js
INSTALL
IMPORT
SIG · REDIS-LUA2JS
R
redis-lua2js
devopsjavascriptv6.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

lua2js
import lua2js from 'redis-lua2js';
const lua2js = require('redis-lua2js');
Default export; ESM-only since v5. CommonJS require will fail with ERR_REQUIRE_ESM.
lua2js (as function)
const result = lua2js(luaScript, { type: 'module' });
const result = lua2js(luaScript, 'module');
Second argument must be an options object, not a string. Options include name, numberOfKeys, and type.
name
const { name } = requireFromString(lua2js(luaScript)); console.log(name);
The exported object contains name, numberOfKeys, and lua. Typically used after parsing the module string with requireFromString or similar.

Shows how to convert a Lua script into a module, load it with ioredis, and run a command.

import { readFileSync } from 'node:fs'; import { join } from 'node:path'; import Redis from 'ioredis'; import lua2js from 'redis-lua2js'; import { requireFromString } from 'module-from-string'; const redis = new Redis(); const lua = readFileSync(join(__dirname, 'pdel.lua'), 'utf8'); const jsModule = lua2js(lua, { type: 'module' }); const pdel = requireFromString(jsModule); redis.defineCommand(pdel.name, { lua: pdel.lua, numberOfKeys: pdel.numberOfKeys, }); const deleted = await redis.pdel('*'); console.log(`Deleted ${deleted} keys`);
Debug
Known issues
breakingVersion 5.x dropped CommonJS support. Default export only available via ESM import.
fix
Use import lua2js from 'redis-lua2js' instead of require().
affects: >=5.0.0
breakingVersion 6.0.0 requires Node.js >=20.0.
fix
Update Node.js to version 20 or later.
affects: >=6.0.0
deprecatedThe 'type' option defaults to 'commonjs' but will default to 'module' in the future.
fix
Explicitly set type: 'module' if you want ESM output, or type: 'commonjs' to maintain current behavior.
affects: >=6.0.0
gotchaThe options object's 'name' and 'numberOfKeys' override parsed values only if provided; otherwise they are parsed from Lua comments.
fix
Ensure Lua script contains comments: -- name <commandname> and -- nkeys <number> if not providing options.
affects: >=1.0.0
gotchaThe output string is a raw module source; it must be evaluated with a module loader (e.g., requireFromString or vm) – it is not a file path.
fix
Use requireFromString from 'module-from-string' or compile with Node's vm module.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module
Using CommonJS require() on an ESM-only package (v5+).
fix
Switch to dynamic import() or ensure your project is configured for ESM (e.g., type: 'module' in package.json).
Cannot find module 'redis-lua2js'
Package is installed as devDependency but used in runtime code.
fix
Move 'redis-lua2js' from devDependencies to dependencies, or use it only in build scripts.
SyntaxError: Unexpected token 'export'
Trying to require() a module that outputs ESM (type: 'module') in a CommonJS context.
fix
Use type: 'commonjs' in options or use dynamic import for the generated module.
Upgrade
Version history
6.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
redis-lua2js — npm install redis-lua2js · libregistry