---
title: getPackageVersion
description: >-
  Get the `version` from a package.json. Accepts either: - A module URL (e.g.
  `import.meta.url`): finds the package.json for that module's package by
  walking up from the file. - A path to package.json (e.g. `resolve(__dirname,
  "../package.json")`): reads that file directly.
updated_at: '2026-03-07T03:07:51+01:00'
created_at: '2026-03-07T03:07:51+01:00'
symbol:
  kind: function
  name: getPackageVersion
  signatures:
    - 'getPackageVersion(urlOrPath: string): string'
  parameters:
    - name: urlOrPath
      type: string
      description: '`import.meta.url` or an absolute path to a package.json file.'
  returns:
    type: string
    description: The `version` string from that package.json.
  throws:
    - type: Error
      description: >-
        If the path points to package.json but has no "version", or if no
        package.json is found when walking up.
  source: >-
    https://github.com/mia-cx/svartz/blob/711f3906a713c8b9a5a572d0f34c85e90c3bc3d1/packages/config/src/utils/package-version.ts#L15
---

# getPackageVersion
