Skip to content

Improve the Could not find root package.json error with hints to workarounds #125

@Delapouite

Description

@Delapouite

Clear and concise description of the problem

Hi

In some of my monorepo projects, I was facing Could not find root package.json error while trying to run node-modules-inspector right at the beginning.

At first I was surprised because npm query :root did find the root package.

After some investigation of the source code, it turns out there's some filtering happening :

  return json.filter((pkg): pkg is NpmPackageNode => {
    return (
      pkg
      && typeof pkg === 'object'
      && typeof pkg._id === 'string'
      && typeof pkg.name === 'string'
      && typeof pkg.version === 'string'
    )
  })

So to be found, the root package.json needs both a name and version fields. In my case it was missing the later (sub-workspaces are versioned independently).

Suggested solution

When the Could not find root package.json is raised, maybe add a small explanation to help the user debug the situation more easily.
For example something like "Ensure that the root package.json has a name and a version"

Thanks

Alternative

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions