Skip to content

fix(tooling): make Prettier plugins resolvable so the pre-commit hook works (#108) - #111

Merged
JOY (JOY) merged 2 commits into
devfrom
claude/nifty-carson-w2lyqn
Oct 16, 2026
Merged

JOY (JOY) merged 2 commits into
devfrom
claude/nifty-carson-w2lyqn

Conversation

@JOY

Copy link
Copy Markdown
Contributor

Summary

What changed? In both Prettier configs, plugins are now resolved with require.resolve from the config file's own package instead of by bare package name:

  • packages/prettier-config/prettier.config.js → prettier-plugin-packagejson
  • apps/web/prettier.config.js → prettier-plugin-tailwindcss (I also formatted this 8-line file with its own config; nothing in lint-staged covers it)

Why? Prettier 3 resolves a bare plugin name from process.cwd() (importPlugin → importFromDirectory(name, cwd)). pnpm installs each package's plugins only under that package's own node_modules. The result: every commit failed at the husky pre-commit step:

[error] Cannot find package 'prettier-plugin-packagejson' imported from /home/user/Rate/noop.js
[error] Cannot find package 'prettier-plugin-packagejson' imported from /home/user/Rate/apps/web/noop.js
husky - pre-commit script failed (code 1)

This hit both the root lint-staged config and apps/web/.lintstagedrc.js. Agents then either skipped the hook or committed unformatted code. pnpm format and pnpm format:check failed the same way. Absolute paths go through pathToFileURL inside Prettier, so the fix works on Windows as well.

Verification (before → after, real git commit with hooks enabled, on throwaway branches):

  • Staged apps/web/.../RadarBadge.tsx, packages/shared-data/src/index.ts and Docs/Resources/ROADMAP.md. Before the fix the commit failed with the errors above (exit 1). After it, the commit succeeded (exit 0) and each staged file was formatted ({a:1, b:"x"} became { a: 1, b: 'x' }).
  • The commits on this branch went through both the pre-commit hook and the commitlint commit-msg hook, with no HUSKY=0.
  • pnpm format:check now runs to completion and lists 158 files that were already not formatted on dev. I deliberately did not mass-format them here, to avoid conflicts with other agents' work in progress. With the hook working, each file gets formatted the next time someone commits it.

Checklist

  • Build passes: shared-data, crawlers, extension, web (Next.js 16), all run locally
  • Type-check passes: pnpm --filter @repo/web typecheck
  • Lint/format: Prettier works again (this is the fix); pnpm format:check executes
  • Tests pass: @repo/crawlers test + test:dist, @repo/extension test, @repo/web test
  • Docs updated: n/a
  • No breaking API changes (tooling config only)

Notes

  • Affected areas: packages/prettier-config, apps/web (Prettier config only)
  • Side effect to expect: because the hook formats every staged file, the first commit that touches an unformatted file will carry formatting-only changes in that file.

Closes #108

🤖 Generated with Claude Code

https://claude.ai/code/session_015v1boe4iagzc2mQVMuU39b


Generated by Claude Code

…fig (#108)

Prettier resolves bare plugin names from process.cwd(), i.e. the repo
root, but pnpm installs @repo/prettier-config's devDependencies only
under packages/prettier-config/node_modules. Every pre-commit run of
lint-staged (and `pnpm format` / `format:check`) therefore failed with
"Cannot find package 'prettier-plugin-packagejson'", so commits either
skipped the hook or landed unformatted.

Resolve the plugin with require.resolve from the config file itself.
Prettier imports absolute plugin paths through pathToFileURL, so this
also works on Windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015v1boe4iagzc2mQVMuU39b
Same root cause as the shared config: Prettier resolves bare plugin
names from process.cwd(), so running Prettier from the repo root
(`pnpm format`, `pnpm format:check`) failed on every apps/web file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015v1boe4iagzc2mQVMuU39b
@coderabbitai

coderabbitai Bot commented Oct 16, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 18 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2e4a741e-7456-4148-a1e3-e8a4bcd7ff39
📥 Commits

Reviewing files that changed from the base of the PR and between 9dfac90 and 9313226.

📒 Files selected for processing: 2
  • apps/web/prettier.config.js
  • packages/prettier-config/prettier.config.js
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@JOY
JOY (JOY) merged commit 51b169f into dev Oct 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(tooling): pre-commit lint-staged fails, prettier cannot resolve prettier-plugin-packagejson

2 participants