{"id":25053,"library":"capnpc-ts","title":"capnpc-ts","description":"Cap'n Proto schema compiler for TypeScript, version 0.7.0. Generates TypeScript type definitions and serialization code from .capnp schema files. Requires the capnp command-line tool (C++ reference implementation). Updated irregularly; key differentiator: enables type-safe Cap'n Proto usage in TypeScript without external RPC dependencies.","status":"active","version":"0.7.0","language":"javascript","source_language":"en","source_url":"https://github.com/jdiaz5513/capnp-ts","tags":["javascript","capnp","rpc","typescript"],"install":[{"cmd":"npm install capnpc-ts","lang":"bash","label":"npm"},{"cmd":"yarn add capnpc-ts","lang":"bash","label":"yarn"},{"cmd":"pnpm add capnpc-ts","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required to compile .capnp schemas; capnpc-ts is a plugin for the capnp tool","package":"capnp","optional":false}],"imports":[{"note":"Package is typically installed globally to use as a CLI tool; dev dependency usage is possible but not common.","wrong":"npm install capnpc-ts --save-dev","symbol":"capnpc-ts","correct":"npm install -g capnpc-ts"},{"note":"The -o option expects the plugin name without 'capnpc-' prefix; use 'ts' not the full package name.","wrong":"capnpc -o capnpc-ts schema.capnp","symbol":"capnpc-ts as a plugin","correct":"capnpc -o ts path/to/schema.capnp"},{"note":"The generated file exports types as named exports; default import will fail unless explicitly set.","wrong":"import MyStruct from './schema.capnp.ts'","symbol":"Generated TS code","correct":"import { MyStruct } from './schema.capnp.ts'"}],"quickstart":{"code":"// Install the compiler globally\nnpm install -g capnpc-ts\n\n// Create a sample schema file: example.capnp\n// @0xbf5147cbbecf40c1;\n// struct Person {\n//   name @0 :Text;\n//   age  @1 :UInt32;\n// }\n\n// Compile the schema\nconst { execSync } = require('child_process');\nexecSync('capnpc -o ts example.capnp', { stdio: 'inherit' });\n\n// Use the generated code\nconst { Person } = require('./example.capnp.ts');\nconst msg = new capnp.Message();\nconst person = msg.initRoot(Person);\nperson.setName('Alice');\nperson.setAge(30);\nconsole.log(person.getName()); // 'Alice'","lang":"javascript","description":"Install capnpc-ts globally, compile a sample .capnp schema to TypeScript, and use the generated code."},"warnings":[{"fix":"Install capnp from https://capnproto.org/install.html or via package manager (e.g., brew install capnp on macOS).","message":"Must have capnp tool installed separately; capnpc-ts does not bundle the Cap'n Proto compiler.","severity":"gotcha","affected_versions":"all"},{"fix":"Be aware that the output path includes the .capnp extension; adjust tsconfig.json if needed to include .ts files.","message":"Generated output file has a .ts extension appended to the original schema file, e.g., myschema.capnp.ts.","severity":"gotcha","affected_versions":"all"},{"fix":"Use -o ts instead of -o capnpc-ts.","message":"Plugin name is 'ts', not 'capnpc-ts'. Using capnpc -o capnpc-ts fails.","severity":"gotcha","affected_versions":"all"},{"fix":"Install @capnp-ts/core as a runtime dependency: npm install @capnp-ts/core.","message":"Generated TypeScript code depends on @capnp-ts/core library for runtime support, but this may not be documented clearly.","severity":"breaking","affected_versions":">=0.6.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure capnpc-ts is installed globally: npm install -g capnpc-ts. Verify plugin is accessible.","cause":"capnpc-ts not installed or not on PATH; capnp cannot find the plugin.","error":"capnpc: Invalid option 'ts'"},{"fix":"Use named import: import { MyStruct } from './my.capnp.ts';","cause":"Using default import when generated code uses named exports.","error":"module '...' has no exported member 'MyStruct'"},{"fix":"Install runtime dependency: npm install @capnp-ts/core (or capnp-ts for older versions).","cause":"Missing runtime dependency @capnp-ts/core (or older capnp-ts package).","error":"Cannot find module 'capnp-ts'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}