Skip to content

bug: package.json not included in exports map — require('@optave/codegraph/package.json') fails #78

@carlos-alm

Description

@carlos-alm

Found during dogfooding v2.2.3-dev.44e8146

Severity: Low
Command: Programmatic API

Reproduction

npm install @optave/codegraph@2.2.3-dev.44e8146
node -e "const p = require('@optave/codegraph/package.json'); console.log(p.version)"

Expected behavior

Should print the package version.

Actual behavior

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in node_modules/@optave/codegraph/package.json

Root cause

The exports field in package.json only maps ".""./src/index.js". It doesn't include "./package.json" as an export.

Suggested fix

Add "./package.json": "./package.json" to the exports map in package.json:

{
  "exports": {
    ".": { "import": "./src/index.js" },
    "./package.json": "./package.json"
  }
}

This is a common pattern used by most npm packages. Tools and bundlers sometimes need to read package.json for version detection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions