Skip to content

fix: don't crash on floating rejections - #2308

Merged
webpro merged 3 commits into
webpro-nl:mainfrom
gioboa:fix/2307
Nov 10, 2026
Merged

webpro merged 3 commits into
webpro-nl:mainfrom
gioboa:fix/2307

Conversation

@gioboa

@gioboa gioboa commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Closes #2307

Log a warning instead of crashing when a loaded config file leaves a rejected promise unhandled, such as next.config.*

@pkg-pr-new

pkg-pr-new Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/knip@2308
npm i https://pkg.pr.new/@knip/language-server@2308
npm i https://pkg.pr.new/@knip/mcp@2308

commit: bd13597

@webpro

webpro commented Nov 8, 2026

Copy link
Copy Markdown
Member

Thanks for the quick pull request, Giorgio. At first sight it looks plain and fine, but trying it out, using a single process.on('unhandledRejection') has a few drawbacks:

  • Swallows any rejection; in Knip itself or custom reporter, from a plugin, it all becomes a warning.
  • A failed run can exitΒ 0, so CI would be green.
  • No attribution to the origin of the exception.
  • The cache seems to keep the faulty result.
  • Not an issue w/ the implementation but the test doesn't test the behavior. Its exit 1 comes from an unused file in the fixture, not from the rejection handling.

So I'd like to try and localize the handling. With the commit I just pushed, the output of running knip from packages/knip/fixtures/plugin-config/floating-rejections seems to do the job.

Analyzing workspace (packages/later-load)…
ERROR: Unhandled rejection, likely from packages/later-load/next.config.js (boom)
ERROR: Please fix or visit https://knip.dev/reference/known-issues
Analyzing workspace (packages/immediate)…
ERROR: Unhandled rejection, likely from packages/immediate/next.config.js (boom)
ERROR: Please fix or visit https://knip.dev/reference/known-issues
Unused files (3)
packages/immediate/src/unused.ts
rejecting-knip.mjs              
rejecting-reporter.mjs          
Unused dependencies (4)
next  packages/immediate/package.json:4:6      
next  packages/late/package.json:4:6           
next  packages/later-load/package.json:4:6     
next  packages/service-starter/package.json:4:6
Unused devDependencies (2)
vite  packages/later-load/package.json:7:6    
vite  packages/service-caller/package.json:4:6
ERROR: Unhandled rejection, likely from packages/service-starter/next.config.js (service boom)
ERROR: Please fix or visit https://knip.dev/reference/known-issues
ERROR: Unhandled rejection, likely from packages/late/next.config.js (boom)
ERROR: Please fix or visit https://knip.dev/reference/known-issues

Would love to hear what you think, @gioboa?

And also to hear from @alxwlw β€” does Knip no longer crash in your project(s)? You can try using the preview release from the pkg-pr-new comment above.

@gioboa gioboa left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @webpro , much better than my global handler. Verified locally: output matches, exit 2, cache entries dropped, tests check the real behavior. Notes: Bun shows no file attribution, and watch mode keeps exiting 2.LGTM.

@webpro

webpro commented Nov 10, 2026

Copy link
Copy Markdown
Member

Thanks for the confirmation! I'm just going to merge, because I want to cut a release and not sure how many Next.js users might be facing the bug.

@webpro
webpro merged commit de958a7 into webpro-nl:main Nov 10, 2026
33 checks passed
@webpro

webpro commented Nov 10, 2026

Copy link
Copy Markdown
Member

πŸš€ This pull request is included in v6.45.0. See Release 6.45.0 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

πŸ”„ Floating rejection in next.config crashes the run since 6.43.0

2 participants