{"id":20229,"library":"nearley-loader","title":"nearley-loader","description":"A webpack loader that imports compiled nearley parser grammar files (`.ne` files) directly into JavaScript modules. Current stable version is 2.0.0, compatible with nearley^2.0.0. It integrates with webpack's module bundling, allowing developers to require grammar files and get compiled parser rules. The loader has a peer dependency on nearley, requiring matching major versions. It is commonly used in projects that build parsers with nearley and bundle with webpack. No release cadence is documented; the package is stable but low-maintenance.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/kozily/nearley-loader","tags":["javascript","loader","webpack"],"install":[{"cmd":"npm install nearley-loader","lang":"bash","label":"npm"},{"cmd":"yarn add nearley-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add nearley-loader","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; nearley-loader compiles nearley grammars and returns a compiled rules object used by nearley's Grammar.fromCompiled().","package":"nearley","optional":false}],"imports":[{"note":"ESM import is correct; import returns the compiled rules object.","wrong":"const grammar = require('./grammar.ne');","symbol":"default import of grammar","correct":"import grammar from './grammar.ne';"},{"note":"Parser and Grammar come from the nearley package, not nearley-loader.","wrong":"import { Parser, Grammar } from 'nearley-loader';","symbol":"Parser and Grammar classes","correct":"import { Parser, Grammar } from 'nearley';"},{"note":"Grammar.fromCompiled must convert the loader's output; passing it directly to Parser will fail.","wrong":"const parser = new Parser(grammar);","symbol":"Grammar.fromCompiled","correct":"const parser = new Parser(Grammar.fromCompiled(grammar));"}],"quickstart":{"code":"// webpack.config.js\nmodule.exports = {\n  module: {\n    rules: [\n      { test: /\\.nearley$/i, use: ['nearley-loader'] },\n    ],\n  },\n};\n\n// yourModule.js\nimport { Parser, Grammar } from 'nearley';\nimport grammar from './grammar.ne';\n\nconst parser = new Parser(Grammar.fromCompiled(grammar));\nparser.feed('some input');\nconsole.log(parser.results);\n","lang":"javascript","description":"Configures webpack to load .nearley files and shows how to use the compiled grammar with nearley's Parser."},"warnings":[{"fix":"Use ESM import syntax (import grammar from './grammar.ne') for clarity.","message":"Requiring a grammar file with CommonJS require will import the compiled rules object as default (not a module.exports keyed object).","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Always use Grammar.fromCompiled(grammar) to get a Grammar instance.","message":"Grammar.fromCompiled must be called on the imported value; passing the raw object to Parser constructor fails.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Install compatible versions: npm install nearley@^2.0.0 nearley-loader@^2.0.0","message":"Major version must match nearley's major version. nearley-loader@2.x works only with nearley@^2.0.0; nearley-loader@1.x with nearley@^1.0.0.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"In CRA, use craco or react-app-rewired to override the webpack config and exclude .nearley from url-loader.","message":"create-react-app applies url-loader to unrecognized extensions; .nearley files may be incorrectly handled without override.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Add a module declaration: declare module '*.nearley' { const rules: any; export default rules; }","message":"TypeScript users may need declarations for .ne files; the package does not export types.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run: npm install --save-dev nearley-loader","cause":"nearley-loader is not installed or is a devDependency not resolved.","error":"Cannot find module 'nearley-loader'"},{"fix":"Ensure nearley-loader is in devDependencies and run npm install.","cause":"Webpack cannot locate the loader, likely missing from node_modules.","error":"Module not found: Error: Can't resolve 'nearley-loader' in ..."},{"fix":"Update nearley to >=2.0.0: npm install nearley@latest","cause":"Using a very old nearley version (before fromCompiled was introduced, e.g. <2.0.0).","error":"TypeError: nearley.Grammar.fromCompiled is not a function"},{"fix":"Use the correct rule definition as shown in the quickstart.","cause":"Loader path or regex may be misconfigured; or webpack version is too old.","error":"The 'nearley-loader' loader is not being recognized in webpack.config.js"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}