{"id":11492,"library":"onnx-proto","title":"ONNX Protobuf Definitions for JavaScript","description":"This `onnx-proto` package provides pre-compiled Protobuf definitions for the Open Neural Network Exchange (ONNX) format, specifically derived from the upstream `onnx/onnx.proto3` file. It enables JavaScript and TypeScript projects to interact with ONNX models by offering type-safe access to the ONNX IR (Intermediate Representation) structures, encompassing messages like `ModelProto`, `GraphProto`, `NodeProto`, and `TensorProto`. The current stable version is 8.0.1, reflecting the latest ONNX IR_VERSION 8 (corresponding to ONNX v1.10.2). Releases are automatically published to npm from the master branch whenever the underlying ONNX definition is updated or significant maintenance occurs, ensuring developers have timely access to the latest ONNX specification. Its key differentiator is being a direct, pre-compiled, and type-safe representation of the official ONNX protobuf schema, saving users the complexity of generating Protobuf code themselves for JavaScript and TypeScript environments.","status":"active","version":"8.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/chaosmail/onnx-proto","tags":["javascript","onnx","protobuf","typescript"],"install":[{"cmd":"npm install onnx-proto","lang":"bash","label":"npm"},{"cmd":"yarn add onnx-proto","lang":"bash","label":"yarn"},{"cmd":"pnpm add onnx-proto","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The 'onnx' object is a namespace containing all compiled protobuf messages, enums, and services. While `require` might work in some transpiled environments, the package is primarily designed for ES module imports as demonstrated in TypeScript examples.","wrong":"const onnx = require('onnx-proto');","symbol":"onnx","correct":"import { onnx } from 'onnx-proto';"},{"note":"Individual ONNX Protobuf messages like `TensorProto` are nested within the top-level `onnx` namespace, not directly exported as root symbols.","wrong":"import { TensorProto } from 'onnx-proto';","symbol":"TensorProto","correct":"import { onnx } from 'onnx-proto'; // Access via onnx.TensorProto"},{"note":"Similar to other protobuf messages, `ModelProto` is accessed as a property of the `onnx` namespace and is not a default export.","wrong":"import ModelProto from 'onnx-proto';","symbol":"ModelProto","correct":"import { onnx } from 'onnx-proto'; // Access via onnx.ModelProto"}],"quickstart":{"code":"import { onnx } from 'onnx-proto';\n\n// Create a simple ONNX TensorProto object\nconst tensorProto = onnx.TensorProto.create({\n  dims: [2, 2],\n  dataType: onnx.TensorProto.DataType.FLOAT,\n  floatData: [1.0, 2.0, 3.0, 4.0]\n});\n\nconsole.log('Created ONNX TensorProto:');\nconsole.log(JSON.stringify(tensorProto.toJSON(), null, 2));\n\n// Access an enum value from the ONNX definition\nconst floatDataType = onnx.TensorProto.DataType.FLOAT;\nconsole.log(`\\nONNX TensorProto.DataType.FLOAT value: ${floatDataType}`);\n\n// This package provides type definitions and constructors for ONNX structures.\n// It does not include an ONNX runtime. For model inference, a separate\n// runtime library (e.g., onnxruntime-web) is required.\n","lang":"typescript","description":"Demonstrates how to import the `onnx` namespace and construct a basic `TensorProto` using its static `create` method, illustrating the package's utility for creating ONNX data structures."},"warnings":[{"fix":"Review the official ONNX release notes for v1.10.2 and migrate any model serialization/deserialization logic to accommodate IR_VERSION 8. Thoroughly test your application with models compiled against the new IR version.","message":"Major version 8.0.0 updates the internal ONNX IR_VERSION to 8, corresponding to ONNX v1.10.2. This may introduce breaking changes if your application relies on specific older IR_VERSION structures or expects backward compatibility with models built against prior ONNX specifications.","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"Consult the changelog for `onnx-proto` and the corresponding ONNX `IR_VERSION` to understand any structural changes introduced by specific package versions.","message":"Older major versions (e.g., 4.0.0, 3.1.0) also updated the underlying ONNX definition, potentially introducing breaking changes in the protobuf structures. Users should always check the upstream ONNX changelog relevant to the `IR_VERSION` noted in the `onnx-proto` version changelog.","severity":"breaking","affected_versions":">=3.1.0"},{"fix":"To perform ONNX model inference in JavaScript environments, use a dedicated ONNX Runtime library such as `onnxruntime-web` or `onnxruntime-node` in conjunction with these definitions for structure validation and serialization.","message":"This package provides only the ONNX Protobuf *definitions* (types, enums, message constructors), not an ONNX runtime or inference engine. Attempting to run or evaluate ONNX models directly with this package will result in errors.","severity":"gotcha","affected_versions":">=3.1.0"},{"fix":"Always use the static `create` method provided on each protobuf message constructor, e.g., `onnx.TensorProto.create({ ... })`.","message":"Protobuf message instances are typically created using static factory methods (e.g., `create()`) rather than direct constructor calls (`new`). Using `new` can lead to runtime errors or unexpected behavior.","severity":"gotcha","affected_versions":">=3.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure you are accessing the specific protobuf message via the `onnx` namespace, like `onnx.TensorProto.create()`.","cause":"Attempting to access a protobuf message constructor (e.g., `TensorProto`) that is nested within the `onnx` namespace directly, rather than through `onnx.TensorProto`.","error":"TypeError: Cannot read properties of undefined (reading 'create')"},{"fix":"Configure your `package.json` with `\"type\": \"module\"` if targeting a pure ES module environment, or use a bundler (e.g., Webpack, Rollup) with Babel or TypeScript to transpile to CommonJS if targeting older Node.js or specific browser environments.","cause":"Attempting to use ES module `import` syntax in a CommonJS environment without proper transpilation or configuration, indicating the runtime does not recognize ES modules.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Always instantiate Protobuf messages using their static `create` method: `onnx.TensorProto.create({ ... })`.","cause":"Incorrect instantiation of a Protobuf message by trying to use `new onnx.TensorProto()` instead of the static `create` method.","error":"TypeError: onnx.TensorProto is not a constructor"}],"ecosystem":"npm"}