slice2js
raw JSON → 3.7.110 verified Fri May 01 auth: no javascript
slice2js is the official Slice-to-JavaScript compiler from ZeroC, part of the Ice RPC framework. It compiles Slice IDL files into JavaScript proxy and skeleton code for building networked applications. The current stable version is 3.7.110 (Ice 3.7.x series). Release cadence follows Ice releases, approximately every 6-12 months. Key differentiator: it's the native compiler for Ice's JavaScript mapping, tightly coupled with the @zeroc/ice npm package. Alternatives like protobuf or Thrift require separate toolchains.
Common errors
error Error: Cannot find module 'slice2js' ↓
cause slice2js is not installed or not in node_modules.
fix
Run 'npm install slice2js --save-dev' in your project directory.
error TypeError: slice2js.compile is not a function ↓
cause Incorrect import: using default import with ESM syntax.
fix
Use const slice2js = require('slice2js'); instead of import.
error slice2js: error: unknown option '--ice' ↓
cause The --ice option was removed in slice2js 3.7.0.
fix
Remove --ice from the arguments; Ice includes are added automatically.
error slice2js: error: Can't open file './Hello.ice' ↓
cause File path is relative to the current working directory, not the Slice file location.
fix
Use an absolute path or set the cwd option: slice2js.compile(['Hello.ice'], { cwd: __dirname }).
Warnings
breaking slice2js v3.8 drops support for Node.js <14 and changes the compiler API. ↓
fix Upgrade to Node.js >=14 and adjust code for any API changes.
breaking slice2js v3.7.0 removed the '--ice' option; Ice includes are now automatic. ↓
fix Remove '--ice' from args. The sliceDir property provides the path if needed.
deprecated The compile function returns a ChildProcess; consider using promises with child_process.execFile. ↓
fix Wrap compile in a promise or use child_process.execFile for simpler error handling.
gotcha slice2js must be installed in the same project as @zeroc/ice to ensure compatible versions. ↓
fix Install both as dependencies: npm install slice2js --save-dev && npm install @zeroc/ice
gotcha Relative paths in args are resolved from the current working directory, not from the Slice file location. ↓
fix Use absolute paths or set the 'cwd' option in the second argument to compile().
Install
npm install slice2js yarn add slice2js pnpm add slice2js Imports
- compile wrong
import { compile } from 'slice2js';correctconst slice2js = require('slice2js'); slice2js.compile(['File.ice']); - sliceDir wrong
const { sliceDir } = require('slice2js');correctconst slice2js = require('slice2js'); const dir = slice2js.sliceDir; - default (require) wrong
import slice2js from 'slice2js';correctconst slice2js = require('slice2js');
Quickstart
const slice2js = require('slice2js');
const path = require('path');
// Compile a Slice file
const child = slice2js.compile(['Hello.ice'], {
cwd: '/path/to/slice',
stdio: 'inherit'
});
child.on('close', (code) => {
if (code !== 0) {
console.error(`slice2js exited with code ${code}`);
process.exit(code);
} else {
console.log('Compilation succeeded');
}
});
console.log('Ice Slice directory:', slice2js.sliceDir);