pip-requirements-js is a pure JavaScript and TypeScript library designed to robustly parse `requirements.txt`, `constraints.txt`, and `requirements.in` files, strictly adhering to pip's documentation on the requirements file format and PEP 508 for dependency specification. The current stable version is 1.0.3, released on March 9, 2026. The project shows an active development cadence, with several releases in late 2025 and early 2026. Its key differentiator is the use of the Ohm.js parser generator, ensuring high fidelity to Python's pip parsing logic, including complex environment markers and file inclusions. It offers both 'full' and 'loose' parsing modes, with options to include source location information for advanced use cases like editor tooling.
npm install pip-requirements-jsVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing a multi-line `requirements.txt` string in both standard and location-inclusive modes, including basic error handling for syntax issues.
Review the API documentation for `parsePipRequirementsFile`, `parsePipRequirementsLine`, and their 'loose' counterparts to adapt to new return types like `WithLocation<T>` and `LooseProjectNameRequirement`.
Always check for `null` when processing the result of `parsePipRequirementsLine` before attempting to access requirement properties. Handle `RequirementsSyntaxError` separately for parsing failures.
When `includeLocations: true` is passed, iterate through the results as `const { data, location } of requirementsWithLocations;` or access `item.data` and `item.location` explicitly.If you need to process all types of pip requirements, including URL-based ones or references to other files, use the 'full' parsing functions (`parsePipRequirementsFile`, `parsePipRequirementsLine`).
Ensure you are using Node.js v12+ and using `import` statements in an ESM context (e.g., in a `.mjs` file or with `"type": "module"` in `package.json`).
Review the exact error message, line, and column reported. Correct the syntax in your `requirements.txt` content to match pip's specifications. Common issues include malformed environment markers, incorrect version specifiers, or invalid options.
Add a null check before accessing properties of the parsed result: `const result = parsePipRequirementsLine(line); if (result) { /* process result.data or result.location */ }`No dependency data recorded yet.