{"id":20186,"library":"lezer-loader","title":"lezer-loader","description":"A webpack loader for Lezer grammar files (.grammar). Currently at version 0.3.0 with a stable API. It enables importing .grammar files as parser modules, supporting external token imports. No configuration options are supported yet. @external imports in grammar files are not tracked as webpack dependencies, requiring manual rebuild triggers. Best paired with @lezer/generator and @lezer/lr for TypeScript usage.","status":"active","version":"0.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/jared-hughes/lezer-loader","tags":["javascript","webpack","lezer","loader"],"install":[{"cmd":"npm install lezer-loader","lang":"bash","label":"npm"},{"cmd":"yarn add lezer-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add lezer-loader","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for grammar generation","package":"@lezer/generator","optional":true}],"imports":[{"note":"Default export is the LRParser instance. Use ESM syntax for webpack.","wrong":"const parser = require('./syntax.grammar')","symbol":"default (parser)","correct":"import parser from './syntax.grammar'"},{"note":"Named exports only exist for external tokens defined in the grammar with @external tokens.","symbol":"named (external tokens)","correct":"import { insertSemi } from './syntax.grammar'"},{"note":"Use type-only imports for TypeScript declarations to avoid runtime overhead.","wrong":"import { LRParser } from '@lezer/lr'","symbol":"type (TypeScript)","correct":"import type { LRParser } from '@lezer/lr'"}],"quickstart":{"code":"// webpack.config.js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.grammar$/,\n        use: 'lezer-loader',\n      },\n    ],\n  },\n};","lang":"javascript","description":"Configures webpack to handle .grammar files with lezer-loader, enabling import of Lezer parsers."},"warnings":[{"fix":"Manually edit the .grammar file (e.g., add a comment or change whitespace) to force webpack to recompile.","message":"@external imports in grammar files are not tracked as webpack dependencies. Edit the grammar file to trigger a rebuild.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Do not pass any options to the loader in webpack config.","message":"No options are supported yet. Attempting to pass options to the loader may break silently.","severity":"breaking","affected_versions":"==0.3.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Add rule { test: /\\.grammar$/, use: 'lezer-loader' } to webpack config.","cause":"Webpack is not configured to handle .grammar files with lezer-loader.","error":"Module parse failed: Unexpected token (1:0) in file.grammar"},{"fix":"Ensure the @external tokens import path in the grammar file is correct and the module is accessible.","cause":"External token import path is incorrect or tokens.js is not in webpack's resolution scope.","error":"Cannot find module './tokens' from 'syntax.grammar'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}