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.
transpileString
✓ import { transpileString } from 'typescript-to-lua'
✗ const transpileString = require('typescript-to-lua').transpileString
ESM-only since v1; CommonJS require() may work but is not recommended.
transpileFiles
✓ import { transpileFiles } from 'typescript-to-lua'
Use for programmatic batch transpilation. Accepts an array of file paths.
LuaTarget
✓ import { LuaTarget } from 'typescript-to-lua'
✗ import LuaTarget from 'typescript-to-lua'
LuaTarget is a named export, not default.
Demonstrates basic programmatic transpilation of a TypeScript function to Lua using transpileString API.
import { transpileString } from 'typescript-to-lua';
const tsCode = `function greet(name: string): string {
return 'Hello, ' + name;
}
`;
const luaCode = transpileString(tsCode, {
luaTarget: '5.3',
sourceMap: true
});
console.log(luaCode);
// Output: local function greet(name)
// return 'Hello, ' .. name
// end
tstl --version
Debug
Known issues
breakingBREAKING CHANGE: TypeScriptToLua v0.20.0 renames the `LuaTarget` enum values to lowercase (e.g., '5.3' previously 'Lua53').fixUpdate enum references: use '5.3', '5.2', etc. instead of 'Lua53', 'Lua52'.
affects: >=0.20.0 <0.21.0
breakingBREAKING CHANGE: v0.36.0 drops support for Node.js <12.fixUpgrade Node.js to v12 or later. Use LTS version.
affects: >=0.36.0
gotchaDefault export changed: in v0.15.0, the default export was the transpiler function; use named exports instead.fixReplace `import tstl from 'typescript-to-lua'` with `import { transpileString } from 'typescript-to-lua'`. affects: >=0.15.0
deprecated`transpile` function is deprecated since v0.30.0; use `transpileString` or `transpileFiles`.fixReplace calls to `transpile` with `transpileString` for single code strings, or `transpileFiles` for files.
affects: >=0.30.0
Errors
Common errors & fixes
Cannot find module 'typescript-to-lua'
Package not installed or not in node_modules.
fixRun: npm install -D typescript-to-lua (or yarn add -D typescript-to-lua)
Error: Invalid Lua target: '5.1'. Must be one of: '5.3', '5.4', 'JIT', '5.2'
Passed '5.1' which is not a valid target; TSTL does not support Lua 5.1 directly.
fixUse one of: '5.2', '5.3', '5.4', 'JIT'. For Lua 5.1 compatibility, use '5.2' or transform manually.
TypeError: transpileString is not a function
Incorrect import (CommonJS vs ESM) or using old API.
fixUse ESM import: import { transpileString } from 'typescript-to-lua'. If using CommonJS, use const { transpileString } = require('typescript-to-lua'). ERROR: The 'transpileFiles' option 'sourceRoot' must be a string.
Passed a non-string value (e.g., number or array) to sourceRoot in options.
fixEnsure sourceRoot is an absolute or relative path string, e.g., './src'.
Audit
Dependencies
lua-typesoptionalTypeScript declarations for Lua standard library and APIs (e.g., math, table)