Registry / serialization / pegjs-loader

pegjs-loader

JSON →
library0.5.8jsnpmunverified

A webpack loader that compiles PEG.js grammar files into JavaScript parser modules. Current version 0.5.8 is stable with weekly npm downloads around 1,000. Requires peer dependencies PEG.js ^0.10.0 and webpack >=1. Supports options like cache, optimize, trace, allowedStartRules, and dependencies. Differentiated from alternatives like jison-loader by its tight integration with PEG.js and support for multiple parser options via query parameters.

npm install pegjs-loader
INSTALL
IMPORT
SIG · PEGJS-LOADER
P
pegjs-loader
serializationjavascriptv0.5.8
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

pegjs-loader
module.exports = { module: { loaders: [{ test: /\.pegjs$/, loader: 'pegjs-loader' }] } }
import pegjs from 'pegjs-loader'
This is a webpack loader, not a JavaScript module. It is configured in webpack.config.js, not imported in application code.
parser
const parser = require('./parser.pegjs');
const parser = require('pegjs-loader!./parser.pegjs');
If configured in webpack config, simply require the .pegjs file. Inline loader syntax is also possible but less common.
parser (with options)
const parser = require('pegjs-loader?cache=true!./parser.pegjs');
const parser = require('./parser.pegjs?cache=true');
Options are passed as query parameters to the loader, not to the grammar file.

Configure webpack to use pegjs-loader on .pegjs files, then require and parse with the compiled parser.

// webpack.config.js module.exports = { entry: './src/index.js', output: { filename: 'bundle.js' }, module: { loaders: [ { test: /\.pegjs$/, loader: 'pegjs-loader?cache=true&optimize=size' } ] } }; // src/index.js const parser = require('./grammar.pegjs'); const result = parser.parse('input string'); console.log(result);
Debug
Known issues
breakingPEG.js updated to 0.10.0, requiring changes in grammar syntax
fix
Update grammars to be compatible with PEG.js 0.10.0. Refer to PEG.js changelog.
affects: >=0.5.0
deprecatedwebpack 1 loaders syntax is deprecated; webpack 2+ uses 'rules' instead of 'loaders'
fix
Use module.rules: [{ test: /\.pegjs$/, use: 'pegjs-loader' }] in webpack 2+.
affects: >=0.5.1
gotchaOptions must be passed as query parameters; they cannot be set in a separate options object
fix
Append options as query string: 'pegjs-loader?cache=true'.
affects: >=0.3.0
breakingPEG.js 0.9.0 breaking changes (e.g., no more global PEG object)
fix
Ensure grammar files are compatible with PEG.js 0.9.0+
affects: >=0.2.1
Errors
Common errors & fixes
Error: Cannot find module 'pegjs'
pegjs not installed in node_modules
fix
npm install --save-dev pegjs
Module build failed: Error: Couldn't find preset 'es2015' relative to directory
Webpack config requires babel-loader for .js files, but pegjs-loader doesn't use babel
fix
Ensure pegjs-loader is not processed by babel; exclude node_modules or pegjs-loader from babel-loader rule
TypeError: Cannot read property 'cacheable' of undefined
Bug in pegjs-loader v0.2.0
fix
Upgrade pegjs-loader to v0.2.2 or later
Error: path must be a string
Passing non-string options as query parameters
fix
Ensure all loader options are strings (e.g., 'true' instead of true)
Upgrade
Version history
0.5.8latest on npm
Audit
Dependencies
pegjsrequiredPeer dependency: compiles grammar files
webpackrequiredPeer dependency: loader runs in webpack
Agent activity
4 hits · last 30 days
node
4
Resources
pegjs-loader — npm install pegjs-loader · libregistry