unjs / unjs/pkg-types

`readPackage`'s `try` option is unimplemented

Open
#257 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
300
Forks
30
Avg merge
20h 45m
Merged PRs (30d)
3

Description

Environment
  • pkg-types: v2.3.0
  • node: v24.13.0
Reproduction

https://stackblitz.com/edit/stackblitz-starters-jg9d7l9r?file=index.js

pnpm install && pnpm dev
Describe the bug

readPackage's options parameter accepts a try boolean option which comes from exsolve's types, and is intended to suppress file-not-found errors and return undefined instead when set to true. Currently, this functionality is not implemented, so errors are thrown even with try: true.

Additional context

No response

Logs
Error: Cannot find matching package.json,package.json5,package.yaml in /foo or parent directories
    at findFile (file:///home/projects/stackblitz-starters-jg9d7l9r/node_modules/.pnpm/pkg-types@2.3.0/node_modules/pkg-types/dist/index.mjs:96:9)
    at async Module.readPackage (file:///home/projects/stackblitz-starters-jg9d7l9r/node_modules/.pnpm/pkg-types@2.3.0/node_modules/pkg-types/dist/index.mjs:174:24)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with readPackage and findFile in dist/index.mjs, at the locations shown in the stack trace, and run the linked StackBlitz reproduction with pnpm install && pnpm dev. Confirm that a missing package file with try: true returns undefined instead of throwing, while ordinary missing-file behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.