{"id":22774,"library":"vite-plugin-peggy-loader","title":"vite-plugin-peggy-loader","description":"Vite plugin that automatically compiles Peggy (PEG.js) grammar files (.pegjs, .peggy) into JavaScript parser modules during the build process. Version 2.0.1 supports Vite and accepts all standard Peggy options (cache, optimize, trace, dependencies, allowedStartRules). Released under MIT license. Alternatives include manual compilation or webpack's peggy-loader; this integrates seamlessly with Vite's plugin system and respects Vite's ESM transform.","status":"active","version":"2.0.1","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","vite","peggy","pegjs","peg.js","peg","loader"],"install":[{"cmd":"npm install vite-plugin-peggy-loader","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-peggy-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-peggy-loader","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency for grammar compilation","package":"peggy","optional":false}],"imports":[{"note":"ESM-only, no CommonJS export. Use dynamic import if needed.","wrong":"const peggyLoader = require('vite-plugin-peggy-loader')","symbol":"default","correct":"import peggyLoader from 'vite-plugin-peggy-loader'"},{"note":"Both default and named exports exist, but default is the common pattern per README.","wrong":"import peggyLoader from 'vite-plugin-peggy-loader'","symbol":"peggyLoader (named)","correct":"import { peggyLoader } from 'vite-plugin-peggy-loader'"},{"note":"Type-only export for options object type, requires TypeScript.","wrong":"import { PeggyOptions } from 'vite-plugin-peggy-loader'","symbol":"PeggyOptions","correct":"import type { PeggyOptions } from 'vite-plugin-peggy-loader'"}],"quickstart":{"code":"import { defineConfig } from 'vite';\nimport peggyLoader from 'vite-plugin-peggy-loader';\n\nexport default defineConfig({\n  plugins: [\n    peggyLoader({\n      cache: true,\n      optimize: 'speed',\n      trace: false\n    })\n  ]\n});","lang":"typescript","description":"Configures Vite to compile .pegjs files on import using Peggy with caching and speed optimization."},"warnings":[{"fix":"Upgrade your grammar toolchain to Peggy >=1.2.0.","message":"Version 2.0.0 dropped support for PEG.js < 1.2.0. Only Peggy ^1.2.0, ^3.0.2, and ^4.0.0 are supported as peer dependencies.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use the `optimize` option instead of `optimizeParser`.","message":"The option `optimizeParser` was renamed to `optimize` in a previous version.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Use `import * as parser from './grammar.pegjs'` and call `parser.parse(input)`.","message":"Importing `.pegjs` files yields a default export that is an object with a `parse` function, not the raw parser function. This differs from some other loaders.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Rename your files to `.pegjs` or modify the plugin's source to include `.peggy`.","message":"The plugin does not support `.peggy` file extension by default; only `.pegjs` is handled.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Manually import the dependency modules in your code or configure Vite to handle them.","message":"The `dependencies` option requires that the parser's dependencies are available at runtime, but this plugin does not automatically include them in the bundle.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run `npm install vite-plugin-peggy-loader`. If using TypeScript, ensure `tsconfig.json` has `\"moduleResolution\": \"node\"` and `\"esModuleInterop\": true`.","cause":"Missing npm install or types not included.","error":"Cannot find module 'vite-plugin-peggy-loader' or its corresponding type declarations."},{"fix":"Use Node >=12.20.0 or <14. It is an ESM package; use dynamic import if CommonJS is required.","cause":"Using a Node.js version that does not support the `exports` field, or the import path is incorrect.","error":"Error: No known conditions for \"./\" specifier in \"vite-plugin-peggy-loader\" package"},{"fix":"Use `import peggyLoader from 'vite-plugin-peggy-loader'` (default import) or `import { peggyLoader } from 'vite-plugin-peggy-loader'` (named import) as available from version 2.0.1.","cause":"Incorrect import: using named import `{ peggyLoader }` when default export is expected, or vice versa.","error":"TypeError: peggyLoader is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}