package-json-type
    Preparing search index...

    Interface IPackageJson

    A TypeScript definition for the package descriptor file.

    interface IPackageJson {
        author?: string | IAuthor;
        bin?: string | IBinMap;
        browser?: string | IBrowserMap;
        bugs?: string | IBugs;
        bundledDependencies?: string[];
        bundleDependencies?: string[];
        config?: IConfig;
        contributors?: (string | IAuthor)[];
        cpu?: CPU[];
        dependencies?: IDependencyMap;
        deprecated?: string;
        description?: string;
        devDependencies?: IDependencyMap;
        devEngines?: IDevEngines;
        directories?: IDirectories;
        engines?: IEngines;
        exports?: string | IConditionalExport | IExportsMap | string[] | null;
        files?: string[];
        flat?: boolean;
        funding?: string | IFunding | IFunding[];
        homepage?: string;
        imports?: IImportsMap;
        jsdelivr?: string;
        keywords?: string[];
        libc?: Libc[];
        license?: SPDXLicenseID | SPDXLicenseIDApproved;
        main?: string;
        maintainers?: (string | IAuthor)[];
        man?: string | string[];
        module?: string;
        name?: string;
        optionalDependencies?: IDependencyMap;
        os?: OS[];
        overrides?: IOverrides;
        packageManager?: string;
        peerDependencies?: IDependencyMap;
        peerDependenciesMeta?: IPeerDependenciesMeta;
        preferGlobal?: boolean;
        private?: boolean;
        publishConfig?: IPublishConfig;
        repository?: string | IRepository;
        resolutions?: { [dependencyName: string]: string };
        scripts?: IScriptsMap | { [scriptName: string]: string };
        sideEffects?: boolean | string[];
        type?: "module" | "commonjs";
        types?: string;
        typesVersions?: ITypesVersions;
        typings?: string;
        unpkg?: string;
        version?: string;
        workspaces?: string[] | IWorkspaces;
        [field: string]: any;
    }

    Indexable

    • [field: string]: any
    Index

    Properties

    author?: string | IAuthor

    Package author information. An author is one person.

    • Shorthand expression
    your-name <account@your-domain> (http://your-url)
    
    bin?: string | IBinMap

    An executable file which will be installed into the PATH with a package install. npm will symlink that file into prefix/bin for global installs, or ./node_modules/.bin/ for local installs.

    {
    "bin" : {
    "myapp" : "./cli.js"
    }
    }

    For example, with linux if you install myapp, it'll create a symlink from the cli.js script to /usr/local/bin/myapp.

    browser?: string | IBrowserMap

    This is a hint to the module which is meant to be used "client-side" instead of "nodejs".

    Can be a string pointing to the browser entry point:

    {
    "browser": "./lib/browser.js"
    }

    Or an object mapping Node.js modules to browser alternatives:

    {
    "browser": {
    "./lib/server.js": "./lib/browser.js",
    "fs": false
    }
    }
    bugs?: string | IBugs

    The url to your project's issue tracker and (or) the email address to which issues should be reported. These are helpful for people who encounter issues with your package.

    bundledDependencies?: string[]

    Bundled dependencies are an array of package names that will be bundled together when publishing your package.

    bundleDependencies?: string[]

    Alias for bundledDependencies. Both spellings are supported by npm.

    config?: IConfig

    A "config" object can be used to set configuration parameters used in package scripts that persist across upgrades. For instance, if a package had the following:

    {
    "config" : {
    "port" : "8080"
    }
    }

    and then had a "start" command that then referenced the npm_package_config_port environment variable, then the user could override that by doing npm config set foo:port 8001.

    contributors?: (string | IAuthor)[]

    If there is an AUTHORS file in the root of your package, npm will treat each line as a Name (url) format, where email and url are optional. Lines which start with a # or are blank, will be ignored.

    cpu?: CPU[]

    If your code only runs on certain cpu architectures, you can specify which ones. This checks against process.arch.

    dependencies?: IDependencyMap

    Dependencies are specified in a simple object that maps a package name to a version range. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or git URL.

    deprecated?: string

    A deprecation message for the package. When set, npm will display a warning when the package is installed. This is typically set via npm deprecate command, but can also be set directly in package.json.

    {
    "deprecated": "This package is no longer maintained. Use 'new-package' instead."
    }
    description?: string

    A brief description of the package. By convention, the first sentence (up to the first ". ") should be usable as a package title in listings.

    devDependencies?: IDependencyMap

    If someone is planning on downloading and using your module in their program, then they probably don't want or need to download and build the external test or documentation framework that you use. In this case, it's best to map these additional items in a devDependencies object.

    devEngines?: IDevEngines

    Development engine requirements. Similar to engines, but these requirements only apply during development (not when the package is used as a dependency).

    {
    "devEngines": {
    "runtime": {
    "name": "node",
    "version": ">=20.0.0"
    },
    "packageManager": {
    "name": "npm",
    "version": ">=10.0.0"
    }
    }
    }
    directories?: IDirectories

    You can specify exact locations to put binary files, man pages, documentation, examples, etc. Package manager tools must use these directory definitions to find various package components.

    {
    "directories": {
    "lib": "path/to/lib/",
    "bin": "path/to/bin/",
    "man": "path/to/man/",
    "doc": "path/to/doc/",
    "example": "path/to/example/"
    }
    }
    engines?: IEngines

    You can specify the version of node that your stuff works on. You can also specify which versions of npm are capable of properly installing your program.

    exports?: string | IConditionalExport | IExportsMap | string[] | null

    The exports field allows defining entry points of a package when imported by name. It takes precedence over the main field and allows restricting access to internal modules.

    {
    "exports": {
    ".": {
    "import": "./dist/esm/index.js",
    "require": "./dist/cjs/index.js"
    },
    "./utils": "./dist/utils.js"
    }
    }
    files?: string[]

    Files that are included in your project described as a glob pattern. Omitting the field will make it default to ["*"], as it will include all files.

    flat?: boolean

    If your package only allows one version of a given dependency, and you'd like to enforce the same behavior as yarn install --flat on the command line, set this to true.

    funding?: string | IFunding | IFunding[]

    Funding information for the package. Provides details on how to financially support the package maintainers.

    {
    "funding": {
    "type": "github",
    "url": "https://github.com/sponsors/user"
    }
    }

    Can also be an array for multiple funding sources:

    {
    "funding": [
    { "type": "github", "url": "https://github.com/sponsors/user" },
    { "type": "opencollective", "url": "https://opencollective.com/project" }
    ]
    }
    homepage?: string

    The url to the project homepage.

    imports?: IImportsMap

    Package imports field for creating internal module aliases. Allows defining import paths that only work within the package itself. All entries must start with # to distinguish them from package specifiers.

    {
    "imports": {
    "#utils": "./src/utils/index.js",
    "#internal/*": "./src/internal/*.js"
    }
    }
    jsdelivr?: string

    Entry point for jsDelivr CDN. Specifies the file to serve when the package is loaded via jsDelivr.

    {
    "jsdelivr": "./dist/index.min.js"
    }
    keywords?: string[]

    An array of string keywords to assist users searching for the package in catalogs.

    libc?: Libc[]

    If your code only runs with certain C library implementations, you can specify which ones. This checks against the C library used by the Node.js runtime.

    {
    "libc": ["glibc"]
    }

    You can also exclude certain implementations:

    {
    "libc": ["!musl"]
    }

    A license for your package so that people know how they are permitted to use it, and any restrictions you're placing on it. If you're using a common license such as BSD-2-Clause or MIT, add a current SPDX license identifier.

    main?: string

    The main field is a module ID that is the primary entry point to your package. That is, if your package is named foo, and a user installs it, and then does require("foo"), then your main module's exports object will be returned. This should be a module ID relative to the root of your package folder. For most modules, it makes the most sense to have a main script and often not much else.

    maintainers?: (string | IAuthor)[]

    A list of people who maintain this package. This field is managed by npm and may not be directly edited. It's populated from the npm registry.

    man?: string | string[]

    A single file (or an array of filenames) for the man program.

    module?: string

    The module field is used by bundlers like webpack and Rollup to detect the ES module entry point of a package. This is an unofficial field but widely adopted by the ecosystem.

    {
    "main": "./dist/cjs/index.js",
    "module": "./dist/esm/index.js"
    }
    name?: string

    The name of your package. The name and version together should form a unique identifier accoss a project. The name and version fields are optional if you don't want to publish your package. A name can be optionally prefixed by a scope, e.g. @types/lodash.

    optionalDependencies?: IDependencyMap

    If a dependency can be used, but you would like npm to proceed if it cannot be found or fails to install, then you may put it in the optionalDependencies object. This is a map of package name to version or url, just like the dependencies object. The difference is that build failures do not cause installation to fail. It is still your program's responsibility to handle the lack of the dependency.

    os?: OS[]

    You can specify which operating systems your module will run on

    overrides?: IOverrides

    Allows overriding versions of nested dependencies. This is useful when you need to fix a security vulnerability or bug in a transitive dependency without waiting for the direct dependency to update.

    {
    "overrides": {
    "foo": "1.0.0",
    "bar": {
    "baz": "2.0.0"
    }
    }
    }
    packageManager?: string

    Defines which package manager is expected to be used when working on the current project. This field is managed by Corepack. Setting this field causes Corepack to ensure the specified package manager version is available and to run it transparently.

    {
    "packageManager": "npm@10.2.0"
    }

    Or with yarn or pnpm:

    {
    "packageManager": "pnpm@8.10.0"
    }
    peerDependencies?: IDependencyMap

    In some cases, you want to express the compatibility of your package with a host tool or library, while not necessarily doing a require of this host. This is usually referred to as a plugin. Notably, your module may be exposing a specific interface, expected and specified by the host documentation.

    peerDependenciesMeta?: IPeerDependenciesMeta

    Provides metadata about peer dependencies, such as marking them as optional. When a peer dependency is marked as optional, npm will not automatically install it and will not emit a warning if it's missing.

    {
    "peerDependencies": {
    "react": "^18.0.0",
    "typescript": "^5.0.0"
    },
    "peerDependenciesMeta": {
    "typescript": {
    "optional": true
    }
    }
    }
    preferGlobal?: boolean

    This option used to trigger an npm warning, but it will no longer warn. It is purely there for informational purposes. It is now recommended that you install any binaries as local devDependencies wherever possible.

    private?: boolean

    If you set "private": true in your package.json, then npm will refuse to publish it. This is a way to prevent accidental publication of private repositories. If you would like to ensure that a given package is only ever published to a specific registry (for example, an internal registry), then use the [[publishConfig]] dictionary described below to override the registry config param at publish-time.

    publishConfig?: IPublishConfig

    This is a set of config values that will be used at publish-time. It's especially handy if you want to set the tag, registry or access, so that you can ensure that a given package is not tagged with “latest”, published to the global public registry or that a scoped module is private by default. Any config values can be overridden, but only "tag", "registry" and "access" probably matter for the purposes of publishing. See npm-config to see the list of config options that can be overridden.

    • Public Registry
    {
    "publishConfig":{
    "registry":"https://registry.npmjs.org"
    }
    }
    • Your Private Registry
    {
    "publishConfig":{
    "registry":"http://your-registry.local"
    }
    }
    repository?: string | IRepository

    Specify the place where your code lives. This is helpful for people who want to contribute.

    • Git
    {
    "repository": {
    "type": "git",
    "url": "https://github.com/ajaxlab/package-json-type.git"
    }
    }
    • Svn
    {
    "repository": {
    "type": "svn",
    "url": "https://v8.googlecode.com/svn/trunk/"
    }
    }
    • Monorepo
    {
    "repository": {
    "type": "git",
    "url": "https://github.com/facebook/react.git",
    "directory": "packages/react-dom"
    }
    }
    resolutions?: { [dependencyName: string]: string }

    Allows you to override a version of a particular nested dependency. See the Selective Versions Resolutions RFC for the full spec. Note that installing dependencies via [yarn install --flat] will automatically add a resolutions block to your package.json file.

    scripts?: IScriptsMap | { [scriptName: string]: string }

    The "scripts" property is a dictionary containing script commands that are run at various times in the lifecycle of your package. The key is the lifecycle event, and the value is the command to run at that point.

    {
    "scripts": {
    "install": "install.js",
    "uninstall": "uninstall.js",
    "build": "build.js",
    "doc": "make-doc.js",
    "test": "test.js",
    }
    }
    sideEffects?: boolean | string[]

    Indicates whether the package has side effects for tree-shaking purposes. When set to false, bundlers like webpack can safely remove unused exports from the bundle.

    {
    "sideEffects": false
    }

    Can also be an array of files that have side effects:

    {
    "sideEffects": [
    "./src/polyfills.js",
    "*.css"
    ]
    }
    type?: "module" | "commonjs"

    Defines the module format for .js files in the package scope. When set to "module", .js files are treated as ES modules. When set to "commonjs" (default), .js files are treated as CommonJS.

    {
    "type": "module"
    }
    types?: string

    Indicate the main declaration file in your package.json. Set the types property to point to your bundled declaration file.

    {
    "name": "some-package",
    "version": "1.0.0",
    "main": "./lib/main.js",
    "types": "./lib/main.d.ts"
    }
    typesVersions?: ITypesVersions

    Allows providing different type definitions for different TypeScript versions. This is useful when your package uses features that are only available in newer TypeScript versions.

    {
    "typesVersions": {
    ">=4.0": {
    "*": ["ts4.0/*"]
    },
    ">=3.0": {
    "*": ["ts3.0/*"]
    }
    }
    }
    typings?: string

    Alias for types. Used to indicate the main TypeScript declaration file. This is the older name for the field, but is still widely supported.

    unpkg?: string

    Entry point for unpkg CDN. Specifies the file to serve when the package is loaded via unpkg.

    {
    "unpkg": "./dist/index.umd.min.js"
    }
    version?: string

    A version string conforming to the Semantic Versioning requirements.

    workspaces?: string[] | IWorkspaces

    Workspaces allow you to manage multiple packages within a single repository (monorepo). Define the workspace packages using glob patterns.

    {
    "workspaces": [
    "packages/*",
    "apps/*"
    ]
    }

    Can also be an object with more options:

    {
    "workspaces": {
    "packages": ["packages/*"],
    "nohoist": ["**/react-native"]
    }
    }