npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@navikt/npm-to-esm

v1.4.0

Published

`npm-to-esm` is a utility for making ESM bundles out of npm-modules fetched off of the npm registry located at registry.npmjs.org.

Readme

npm-to-esm

npm-to-esm is a utility for making ESM bundles out of npm-modules fetched off of the npm registry located at registry.npmjs.org.

Description

It does this by fetching a specified NPM-module from the registry to your file system, and using a specified entrypoint, it runs the contents of the module through a Rollup build that is setup and executed here, putting the resulting contents in an outputFile of your choice (or ./index.esm.js from where you are running it by default).

It has been tested using modules that are on CommonJS and ESM formats respectively. However, it should be considered a best-effort and it may not work for your use-case - this util is still very much a work in progress.

Getting started

To install the package from the NPM registry:

npm install -g @navikt/npm-to-esm

Usage example:

npm-to-esm --packageName @navikt/ds-react --packageVersion 0.14.3-beta.1 --entry ./esm/index.js

You may also require it from Node.js and provide options as an argument:

const npmToEsm = require('@navikt/npm-to-esm');

async function myFunction() {
    const rollupOutput = await npmToEsm({ 
        packageName: '@navikt/ds-react', 
        packageVersion: '0.16.8'
        // ... other options
    })
}

Options

| Option | Description | Required / Optional | Default value | Example | | --- | --- | --- | --- | --- | | --packageName <packageName> | The desired package from NPM registry | required | | | | --packageVersion <version> | Version of the desired package | required | | | | --entry <path to entrypoint> | Custom entrypoint to build from (relative to root of the specified package) | optional | | | | --includeDependencies | Whether or not to include dependencies of the package in the resulting ESM bundle | optional | | | | --importMap <path to file> | Path to a file containing an import map in valid JSON format. Uses this rollup-plugin to translate imports to use specified URLs instead (see example). Takes precedence over --includeDependencies for imports included in the import map. | optional | | { "react": "https://<my-cool-cdn>/react.esm.js" } | | --outputFile <path to file> | Where to output the finished bundle | optional | ./index.js | |

Replacing strings in output build

If you want to modify the output of the rollup build before writing the contents to a file, the rollup-build has been configured with usage of rollup's replace plugin, and providing a custom config object to this plugin is supported when using npm-to-esm from Node.js (please read the docs for @rollup/plugin-replace for how to configure it for your use case).

Example:

const npmToEsm = require('@navikt/npm-to-esm');

async function myFunction() {
    const rollupOutput = await npmToEsm({ 
        packageName: '@navikt/ds-react', 
        packageVersion: '0.16.8'
        replaceConfig: {
            delimiters: ['', ''],
            values: {
                'process.env.NODE_ENV': JSON.stringify('production'),
                'import { myNamedExport }': 'import myDefaultExport' 
            }
        }
    })
}

Please note: The replace plugin does have a default configuration set up in the rollup build, regardless of whether npm-to-esm is being used from Node.js or CLI.

Currently, it is configured with this by default:

{
    preventAssignment: true,
    'process.env.NODE_ENV': JSON.stringify('production'),
};

Contact

Questions regarding the code may be asked as issues to this GitHub repository.

For NAV-employees

Interne henvendelser kan sendes via Slack i kanalen #personbruker-teknisk.