Registry / data / gerber-parser

gerber-parser

JSON →
library4.2.7jsnpmunverified

gerber-parser is a JavaScript/TypeScript library that provides a streaming parser for Gerber (RS-274X) and NC drill files, commonly used for Printed Circuit Board (PCB) manufacturing. It functions as a Node.js transform stream, taking a text stream of a Gerber file and emitting structured JavaScript objects representing the file's contents, which can then be consumed by PCB visualization or plotting tools. The library is part of the Tracespace collection of open-source PCB visualization tools. The current stable version is 4.2.7. While a precise release cadence isn't explicitly stated, the project maintains an active development cycle within the Tracespace ecosystem, with major versions introducing breaking changes to improve parsing accuracy and specification compliance. Its key differentiator is its streaming architecture, allowing efficient processing of large Gerber files without loading the entire content into memory, and its explicit focus on the Gerber X2 standard for enhanced data integrity.

npm install gerber-parser
INSTALL
IMPORT
SIG · GERBER-PARSER
G
gerber-parser
datajavascriptv4.2.7
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

gerberParser
✓ import gerberParser from 'gerber-parser';
✗ import { gerberParser } from 'gerber-parser'; const gerberParser = require('gerber-parser').default;
The primary parser function is a default export, instantiating the transform stream.
gerberParser (CommonJS)
✓ const gerberParser = require('gerber-parser');
✗ import gerberParser from 'gerber-parser';
For Node.js environments still using CommonJS, `require` is the correct method, as the package exports the function directly as the module.exports.
Parser (Type)
✓ import type { Parser } from 'gerber-parser';
When using TypeScript, import the `Parser` type for type-hinting the stream instance.

Demonstrates how to create a `gerber-parser` instance, pipe a Gerber file stream into it, and handle data, warnings, and completion events.

import fs from 'fs'; import gerberParser from 'gerber-parser'; import type { Parser } from 'gerber-parser'; // Create a dummy Gerber file for demonstration const dummyGerberContent = ` %FSLAX26Y26*% %MOIN*% %LPD*% G01*% D10*X1000000Y1000000*D03*% M02*% `; const dummyGerberPath = 'dummy_file.gbr'; fs.writeFileSync(dummyGerberPath, dummyGerberContent); const parser: Parser = gerberParser(); parser.on('warning', (w) => { console.warn(`Warning at line ${w.line}: ${w.message}`); }); parser.on('data', (obj) => { // Each 'data' event emits a parsed Gerber object console.log(JSON.stringify(obj, null, 2)); }); parser.on('end', () => { console.log('Gerber file parsing complete.'); fs.unlinkSync(dummyGerberPath); // Clean up dummy file }); parser.on('error', (err) => { console.error('Error during parsing:', err.message); fs.unlinkSync(dummyGerberPath); // Clean up dummy file on error }); // Pipe the stream into the parser fs.createReadStream(dummyGerberPath) .pipe(parser);
Debug
Known issues
breakingVersion 4.0.0 of `gerber-parser` explicitly accepts only Gerber X2 (or drill) files by default. Passing a non-X2 Gerber file will now throw an error.
fix
Ensure all Gerber files passed to the parser conform to the Gerber X2 standard. If processing older Gerber files is necessary, consult the API documentation for options to disable this strict validation, though it's not recommended for production.
affects: >=4.0.0
gotchaBrowser usage requires bundling. If using in a browser environment without a build tool (like Webpack or Browserify), you must use the pre-built `gerber-parser.min.js` script and access the library via the global `gerberParser` variable.
fix
For modern browser applications, bundle `gerber-parser` using a module bundler. For simple script tag inclusion, ensure you use the `dist/gerber-parser.min.js` file and access the global `gerberParser` variable.
affects: >=1.0.0
gotchaThe parser emits `warning` events for non-critical issues or deviations from best practices in the Gerber file. These are not errors but can indicate potential problems or non-standard syntax.
fix
Always attach an `on('warning', handler)` listener to the parser stream to log or handle these warnings. This helps identify and address potential issues in the Gerber input files.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Not a Gerber X2 file
Attempting to parse an older Gerber RS-274D file or a malformed Gerber file with `gerber-parser` v4+ without disabling strict X2 validation.
fix
Convert the Gerber file to the X2 standard or ensure it is a valid X2 file. Alternatively, if explicitly needed and understood, consult the `gerber-parser` API documentation for options to relax X2 strictness (though generally not recommended).
TypeError: gerberParser is not a function
Incorrectly importing or requiring the `gerber-parser` module, attempting to `new` the result, or misusing CommonJS `require` with an ES module setup.
fix
For ES Modules, use `import gerberParser from 'gerber-parser';`. For CommonJS, use `const gerberParser = require('gerber-parser');`. The module exports a function that you call directly to get a stream instance (e.g., `const parser = gerberParser();`).
Upgrade
Version history
4.2.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Bingbot
1
Resources
gerber-parser — npm install gerber-parser · libregistry