{"id":26398,"library":"slice2js","title":"slice2js","description":"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.","status":"active","version":"3.7.110","language":"javascript","source_language":"en","source_url":"https://github.com/zeroc-ice/ice","tags":["javascript","Ice","Slice","compiler","rpc"],"install":[{"cmd":"npm install slice2js","lang":"bash","label":"npm"},{"cmd":"yarn add slice2js","lang":"bash","label":"yarn"},{"cmd":"pnpm add slice2js","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime Ice library required to use compiled JavaScript proxies/skeletons.","package":"@zeroc/ice","optional":false}],"imports":[{"note":"slice2js is a CommonJS module; no ESM export. Use require() only.","wrong":"import { compile } from 'slice2js';","symbol":"compile","correct":"const slice2js = require('slice2js'); slice2js.compile(['File.ice']);"},{"note":"sliceDir is a property of the default export, not a named export.","wrong":"const { sliceDir } = require('slice2js');","symbol":"sliceDir","correct":"const slice2js = require('slice2js'); const dir = slice2js.sliceDir;"},{"note":"slice2js is CommonJS-only; ES6 import does not work.","wrong":"import slice2js from 'slice2js';","symbol":"default (require)","correct":"const slice2js = require('slice2js');"}],"quickstart":{"code":"const slice2js = require('slice2js');\nconst path = require('path');\n\n// Compile a Slice file\nconst child = slice2js.compile(['Hello.ice'], {\n  cwd: '/path/to/slice',\n  stdio: 'inherit'\n});\n\nchild.on('close', (code) => {\n  if (code !== 0) {\n    console.error(`slice2js exited with code ${code}`);\n    process.exit(code);\n  } else {\n    console.log('Compilation succeeded');\n  }\n});\n\nconsole.log('Ice Slice directory:', slice2js.sliceDir);","lang":"javascript","description":"Demonstrates how to import slice2js, compile a Slice file, handle exit codes, and access the built-in Slice include path."},"warnings":[{"fix":"Upgrade to Node.js >=14 and adjust code for any API changes.","message":"slice2js v3.8 drops support for Node.js <14 and changes the compiler API.","severity":"breaking","affected_versions":">=3.8.0"},{"fix":"Remove '--ice' from args. The sliceDir property provides the path if needed.","message":"slice2js v3.7.0 removed the '--ice' option; Ice includes are now automatic.","severity":"breaking","affected_versions":">=3.7.0 <3.8"},{"fix":"Wrap compile in a promise or use child_process.execFile for simpler error handling.","message":"The compile function returns a ChildProcess; consider using promises with child_process.execFile.","severity":"deprecated","affected_versions":"all"},{"fix":"Install both as dependencies: npm install slice2js --save-dev && npm install @zeroc/ice","message":"slice2js must be installed in the same project as @zeroc/ice to ensure compatible versions.","severity":"gotcha","affected_versions":"all"},{"fix":"Use absolute paths or set the 'cwd' option in the second argument to compile().","message":"Relative paths in args are resolved from the current working directory, not from the Slice file location.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'npm install slice2js --save-dev' in your project directory.","cause":"slice2js is not installed or not in node_modules.","error":"Error: Cannot find module 'slice2js'"},{"fix":"Use const slice2js = require('slice2js'); instead of import.","cause":"Incorrect import: using default import with ESM syntax.","error":"TypeError: slice2js.compile is not a function"},{"fix":"Remove --ice from the arguments; Ice includes are added automatically.","cause":"The --ice option was removed in slice2js 3.7.0.","error":"slice2js: error: unknown option '--ice'"},{"fix":"Use an absolute path or set the cwd option: slice2js.compile(['Hello.ice'], { cwd: __dirname }).","cause":"File path is relative to the current working directory, not the Slice file location.","error":"slice2js: error: Can't open file './Hello.ice'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}