{"id":20258,"library":"pegjs-loader","title":"pegjs-loader","description":"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.","status":"active","version":"0.5.8","language":"javascript","source_language":"en","source_url":"https://github.com/eploko/pegjs-loader","tags":["javascript","webpack","pegjs","peg.js","peg","loader"],"install":[{"cmd":"npm install pegjs-loader","lang":"bash","label":"npm"},{"cmd":"yarn add pegjs-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add pegjs-loader","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: compiles grammar files","package":"pegjs","optional":false},{"reason":"Peer dependency: loader runs in webpack","package":"webpack","optional":false}],"imports":[{"note":"This is a webpack loader, not a JavaScript module. It is configured in webpack.config.js, not imported in application code.","wrong":"import pegjs from 'pegjs-loader'","symbol":"pegjs-loader","correct":"module.exports = { module: { loaders: [{ test: /\\.pegjs$/, loader: 'pegjs-loader' }] } }"},{"note":"If configured in webpack config, simply require the .pegjs file. Inline loader syntax is also possible but less common.","wrong":"const parser = require('pegjs-loader!./parser.pegjs');","symbol":"parser","correct":"const parser = require('./parser.pegjs');"},{"note":"Options are passed as query parameters to the loader, not to the grammar file.","wrong":"const parser = require('./parser.pegjs?cache=true');","symbol":"parser (with options)","correct":"const parser = require('pegjs-loader?cache=true!./parser.pegjs');"}],"quickstart":{"code":"// webpack.config.js\nmodule.exports = {\n  entry: './src/index.js',\n  output: { filename: 'bundle.js' },\n  module: {\n    loaders: [\n      {\n        test: /\\.pegjs$/,\n        loader: 'pegjs-loader?cache=true&optimize=size'\n      }\n    ]\n  }\n};\n\n// src/index.js\nconst parser = require('./grammar.pegjs');\nconst result = parser.parse('input string');\nconsole.log(result);","lang":"javascript","description":"Configure webpack to use pegjs-loader on .pegjs files, then require and parse with the compiled parser."},"warnings":[{"fix":"Update grammars to be compatible with PEG.js 0.10.0. Refer to PEG.js changelog.","message":"PEG.js updated to 0.10.0, requiring changes in grammar syntax","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"Use module.rules: [{ test: /\\.pegjs$/, use: 'pegjs-loader' }] in webpack 2+.","message":"webpack 1 loaders syntax is deprecated; webpack 2+ uses 'rules' instead of 'loaders'","severity":"deprecated","affected_versions":">=0.5.1"},{"fix":"Append options as query string: 'pegjs-loader?cache=true'.","message":"Options must be passed as query parameters; they cannot be set in a separate options object","severity":"gotcha","affected_versions":">=0.3.0"},{"fix":"Ensure grammar files are compatible with PEG.js 0.9.0+","message":"PEG.js 0.9.0 breaking changes (e.g., no more global PEG object)","severity":"breaking","affected_versions":">=0.2.1"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"npm install --save-dev pegjs","cause":"pegjs not installed in node_modules","error":"Error: Cannot find module 'pegjs'"},{"fix":"Ensure pegjs-loader is not processed by babel; exclude node_modules or pegjs-loader from babel-loader rule","cause":"Webpack config requires babel-loader for .js files, but pegjs-loader doesn't use babel","error":"Module build failed: Error: Couldn't find preset 'es2015' relative to directory"},{"fix":"Upgrade pegjs-loader to v0.2.2 or later","cause":"Bug in pegjs-loader v0.2.0","error":"TypeError: Cannot read property 'cacheable' of undefined"},{"fix":"Ensure all loader options are strings (e.g., 'true' instead of true)","cause":"Passing non-string options as query parameters","error":"Error: path must be a string"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}