How UNPKG Resolves a Package's Default Entry Point

When you request a package from UNPKG without a file path, UNPKG resolves the file using the package's default entry point. For packages that use the exports field, it resolves using the default export condition. For older packages without exports, it falls back to the main field in package.json. If you want a specific file instead, include the path in the URL.

The URL pattern

UNPKG serves any file on npm through a URL of this shape:

https://unpkg.com/:package@:version/:file
Segment Meaning
:package The package name on npm
:version A version, npm dist-tag, or semver range (optional)
:file Path to a file inside the package (optional)

If you omit the version, the latest tag is used. If you omit the file path, UNPKG resolves the default entry point.

How the default entry point is chosen

The resolution depends on how the package declares its entry points.

Packages using exports

Modern packages declare entry points with the exports field. UNPKG resolves the file using the default export condition.

For example, given this package.json:

{
  "name": "my-package",
  "exports": {
    "default": "./dist/index.js"
  }
}

You can load the package with just the package name:

<script src="https://unpkg.com/my-package"></script>

Packages using main

For packages meant for frontend development that don't use exports — jQuery and GSAP are the examples UNPKG gives — the default entry point is the value of the main field in package.json.

https://unpkg.com/jquery
https://unpkg.com/gsap

Subpaths and custom conditions

The full exports spec is supported, including subpaths. If a package declares:

{
  "name": "my-package",
  "exports": {
    "./exp": {
      "default": "./dist/exp.js"
    }
  }
}

You can load that subpath directly:

<script src="https://unpkg.com/my-package/exp"></script>

Custom export conditions are supported through the ?conditions query parameter, which lets you load a different file based on the environment or other conditions. To fetch React using the react-server condition:

fetch("https://unpkg.com/react?conditions=react-server")

Browsing and pinning versions

Add a trailing / to a directory URL to see a listing of every file in that directory:

https://unpkg.com/react/
https://unpkg.com/preact/src/

To browse an older version, put the version in the URL:

https://unpkg.com/react@18/
https://unpkg.com/react-router@5/

You can also use any valid semver range or npm tag, such as preact@latest or react@^18.

Practical takeaways

  • Omit the file path only when you trust the package's default entry point. If you need a specific build, name the file explicitly.
  • Pin a version in production. A bare package name resolves to latest, which can change without warning.
  • Use ?conditions when a package ships environment-specific builds and you need one that isn't the default.
  • Check the directory listing first if you're unsure which files a package ships — append / to the package or version URL.
unpkg.com
The CDN for everything on npm