Skip to content

Conversation

mbhargav294
Copy link

Fix package.json import error in CLI build that caused module resolution failure in production

Motivation and Context

The CLI was failing in production builds with "Cannot find module '../package.json'" error because the relative import path didn't resolve correctly from the compiled JavaScript in the build directory. This prevented the CLI from working when installed via npm/npx.

How Has This Been Tested?

  • All existing CLI tests pass (56 tests total)
  • Build completes successfully without errors
  • Tested npm run dev script for local development
  • Verified package info is correctly extracted and accessible

Breaking Changes

None. This is a build-time fix that doesn't change the CLI's public API or behavior.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

  • Added prebuild script using jq to extract only needed package fields (version, name, description)
  • Created CLI README with development examples for contributors
  • Added pkgInfo.json to .gitignore to prevent committing generated files
  • Solution maintains same import pattern while fixing build-time resolution

Fixes #834

- Add prebuild script to extract package info to src/pkgInfo.json
- Update import to use generated pkgInfo.json instead of ../package.json
- Add dev script for local CLI testing
- Create CLI README with development examples
- Add pkgInfo.json to .gitignore

Fixes modelcontextprotocol#834
@mbhargav294 mbhargav294 marked this pull request as ready for review October 2, 2025 03:55
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.

ERR_MODULE_NOT_FOUND: CLI fails to locate package.json when starting inspector with --cli flag
1 participant