{"id":17439,"library":"fixpack","title":"Fixpack: package.json Scrubber","description":"fixpack is a command-line interface (CLI) tool designed to enforce a consistent structure and content within `package.json` files. It automates the reordering of top-level keys, alphabetically sorts `dependencies` and `devDependencies`, and ensures a newline at the end of the file. The tool also provides configurable warnings for missing recommended fields (e.g., `description`, `author`, `license`) and errors for missing required fields (e.g., `name`, `version`). A key differentiator is its ability to tolerate malformed JSON using the `alce` library, making it robust against minor syntax errors. The current stable version is 4.0.0, though the project's update cadence appears irregular, with previous major updates and patch fixes spanning several years. It supports extensive configuration via `.fixpackrc` files and CLI arguments, and can be integrated into CI/CD pipelines using its `--dryRun` flag to check for compliance without modifying files.","status":"active","version":"4.0.0","language":"javascript","source_language":"en","source_url":"git://github.com/henrikjoreteg/fixpack","tags":["javascript","cleanup","package"],"install":[{"cmd":"npm install fixpack","lang":"bash","label":"npm"},{"cmd":"yarn add fixpack","lang":"bash","label":"yarn"},{"cmd":"pnpm add fixpack","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used to parse potentially malformed JSON from package.json files, increasing robustness.","package":"alce","optional":false},{"reason":"Handles configuration loading from .fixpackrc files, environment variables, and CLI arguments.","package":"rc","optional":false}],"imports":[{"note":"fixpack is primarily a command-line interface (CLI) tool and is not typically used via programmatic imports in JavaScript/TypeScript code. Its functionality is accessed by executing the `fixpack` command in the terminal.","symbol":"fixpack CLI","correct":"npm i -g fixpack\nfixpack"}],"quickstart":{"code":"npm i -g fixpack\n\n# Navigate to your project directory\ncd my-project\n\n# Run fixpack to clean up package.json\nfixpack\n\n# Example of using fixpack after installing a new package\nnpm i cool_package --save && fixpack\n\n# Check if package.json needs fixing without modifying it (for CI/CD)\n# This will exit with code 1 if changes are needed, 0 if already fixed.\nfixpack --dryRun\n","lang":"javascript","description":"Demonstrates global installation and execution of fixpack, including its use in a post-install hook and a dry run for CI checks."},"warnings":[{"fix":"Create a `.fixpackrc` file in your project root or home directory, or pass configuration options directly as CLI arguments (e.g., `fixpack --indent 2`).","message":"Version 2.0.0 introduced configuration via a `.fixpackrc` file or CLI arguments, replacing previous configuration methods. Users upgrading from earlier versions may need to create a `.fixpackrc` file or adjust their command-line usage.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always commit your `package.json` to version control before running `fixpack`, or use the `--dryRun` flag first to preview changes. For critical environments, consider piping the output of `fixpack` to a temporary file before overwriting.","message":"By default, `fixpack` modifies your `package.json` file in place without creating a backup. This can be destructive if not used carefully.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Ensure all fields listed in your `required` configuration are present in `package.json`. Adjust the `required` array in your `.fixpackrc` if certain fields are not strictly necessary for your project.","message":"The `required` configuration option (defaulting to `name` and `version`) will cause `fixpack` to exit with an error (non-zero exit code) if any of these fields are missing. This is intentional for CI, but can unexpectedly halt processes.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"When integrating into CI, explicitly check for exit code `0` for success if the goal is to ensure an already fixed `package.json`. If using `--dryRun` as a check, an exit code of `1` indicates a non-compliant file.","message":"The `fixpack` command exits with code `1` if changes were made to `package.json` (or if changes *would* be made when using `--dryRun`), and `0` if the file was already correctly formatted. This behavior is designed for CI checks but can be misinterpreted as an error.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Only use `fixpack --wipe` if you understand its implications and intend to immediately follow up with `npm update --save && npm update --save-dev` or similar commands to reinstall specific version ranges. Avoid using it generally.","message":"The `wipe` option will destructively set all dependency versions in `dependencies` and `devDependencies` to `*`. This is intended for specific workflows (e.g., bulk updates) and should be used with extreme caution as it removes explicit version ranges.","severity":"gotcha","affected_versions":">=2.3.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure you are running `fixpack` from the root directory of your project, or a subdirectory where a `package.json` can be found in a parent directory.","cause":"The `fixpack` command was executed in a directory that does not contain a `package.json` file, and no `package.json` was found in any parent directories up to the root.","error":"Error: package.json not found in current directory or any parent directories."},{"fix":"Install `fixpack` globally using `npm i -g fixpack` or `yarn global add fixpack`. If it's already installed globally, check your shell's PATH configuration to ensure the npm global bin directory is included.","cause":"The `fixpack` executable is not in your system's PATH, typically because it was not installed globally or the global `node_modules/.bin` directory is not in your PATH.","error":"fixpack: command not found"},{"fix":"If running interactively, this means your `package.json` was fixed. If in CI and `--dryRun` was used, it means the `package.json` was not compliant. Review the output for warnings/errors and ensure your `package.json` meets the configured requirements. Run `fixpack` without `--dryRun` to apply changes.","cause":"This exit code indicates that `fixpack` either made changes to `package.json` or, if `--dryRun` was used, detected that changes were necessary to bring the file into compliance. This is part of its intended behavior for CI checks.","error":"fixpack exited with code 1"}],"ecosystem":"npm","meta_description":null}