DevTools Logo

package.json Generator

package.json Generator

Scaffold a modern package.json with exports, scripts, engines and validation.

Runs in your browser
Try an example

Package fields

11 fields
Scripts
Dependencies
Dev dependencies

package.json

27 lines · 474 chars
No validation issues found.
{
  "name": "my-lib",
  "version": "1.0.0",
  "type": "module",
  "main": "./dist/index.js",
  "module": "./dist/index.js",
  "types": "./dist/index.d.ts",
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "import": "./dist/index.js"
    },
    "./package.json": "./package.json"
  },
  "files": [
    "dist"
  ],
  "scripts": {
    "build": "tsc -p tsconfig.json",
    "test": "vitest run"
  },
  "engines": {
    "node": ">=20"
  },
  "license": "MIT"
}

Details

npm init produces a bare minimum file, while modern packages need deliberate entry points. This generator emits a key-ordered manifest with only non-empty fields: identity, type, main/module/types, conditional exports, bin, files, sideEffects, scripts, engines, packageManager, keywords, author, license and sorted dependencies. Live checks cover npm naming rules, semver versions and ranges, exports subpath syntax and bin paths. Issues are listed beneath the preview but never block it, so you can see the file while fixing a typo. Four templates seed the whole form.

ESM library

"exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" } }

Conditions are ordered with types first so TypeScript resolves the declarations.

CLI package

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

The bin map is emitted with relative paths; the target file still needs a shebang.

Engines range

"engines": { "node": ">=20 <23" }

Comparator ranges are validated and emitted without a leading v prefix.

Examples

ESM library

Input
name my-lib, type module, exports . → dist/index.js
Output
"exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" } }

Conditional exports give modern bundlers the right artifact while preserving type resolution.

CLI package

Input
bin mycli → ./bin/cli.js
Output
"bin": { "mycli": "./bin/cli.js" }

The bin map is emitted with sorted names and a note that the target file needs a shebang.

Engines range

Input
>=20 <23
Output
"engines": { "node": ">=20 <23" }

Common comparator ranges are accepted; a bare v prefix or missing comparator is flagged instead of silently emitted.

About this tool

The package.json Generator produces a modern, key-ordered manifest from a form: identity fields, entry points, exports conditions, scripts, engines, files, bin and dependencies. Empty fields are omitted, so the preview stays copy-paste ready instead of carrying npm init placeholders.

Live validation checks npm naming rules, semver versions and ranges, exports subpath keys and dependency syntax. Issues appear as a list with field references, but they never block the preview, so you can see what the generated file will look like while fixing a typo.

Templates for an ESM library, CLI, Node app and TypeScript package preset the whole form. Everything is computed in the browser; no registry is contacted and no package is installed.

What this tool does not do

  • Validation is structural and syntactic; the tool cannot check that referenced files exist or that a package name is available.
  • Workspaces, monorepo layouts and lockfile generation are out of scope.
  • The private flag is emitted as a boolean only; publish policies depend on your registry configuration.

How to use this tool

  1. Start from a template

    Choose ESM library, CLI, Node app or TypeScript package to seed sensible defaults.

  2. Fill identity and entry points

    Set name, version, type, main/module/types and an exports map for the public subpaths.

  3. Add scripts and dependencies

    Use add-row controls for scripts and name@range dependency entries; duplicates are merged deterministically.

  4. Read validation and export

    Resolve any issues listed below the preview, then copy the JSON or download package.json.

Use cases

Library scaffolding

Publish a package with a correct exports map instead of hand-editing npm init output.

Team templates

Standardize scripts, engines and license fields across new repositories.

Teaching npm

Show how each key affects installs and resolution while the JSON updates live.

Emitted key order

OrderKey
1name, version, description, private
2type, main, module, types, exports, bin, files, sideEffects
3scripts, engines, packageManager
4keywords, author, license
5dependencies, devDependencies

Exports conditions are written with types first, then import and require, because condition order affects resolution.

Common mistakes

Mistake:Using both main and a conflicting exports map.

Fix:exports takes precedence for supported resolvers. Keep main as a fallback for older tooling and point both at the same artifact.

Mistake:Listing condition keys as package subpaths.

Fix:Subpath keys must be . or start with ./; import, require and types are conditions inside a subpath object.

Mistake:Publishing uppercase or scoped names with invalid characters.

Fix:npm names must be lowercase and URL-safe, at most 214 characters, and may not start with a dot or underscore.

Frequently asked questions

What fields does a modern package.json need?

At minimum name and version. For a publishable library you also want a description, license, type, entry points (main/types or exports), files allowlist, scripts and engines. This generator emits those keys in a stable order and omits empty ones, so the preview stays ready to copy.

How does the exports map work?

exports defines the public subpaths of a package. Each key must be . or start with ./, and each target must be a relative ./ path. Values can be a single string or conditions such as types, import and require. Conditions are written types first because Node and bundlers resolve them in order.

Should I set type to module?

Set "type": "module" when your JavaScript uses ESM syntax directly, and leave it unset or commonjs for require-based packages. With exports maps the two entry points can differ, so a dual package can offer import and require targets while the type field still controls .js parsing.

What is the difference between main, module and exports?

main is the legacy CommonJS entry that old resolvers use. module is an unofficial bundler convention for ESM. exports is the modern authoritative map: when present, supported resolvers ignore main for subpaths it defines. Keep main as a fallback pointing at the same artifact.

What files should I publish?

Use the files allowlist to ship only the built artifact (for example dist), plus README and LICENSE which npm includes automatically. The tool cannot check that listed paths exist, so verify with npm pack --dry-run before publishing.

Does the tool contact npm?

No. Validation is structural and syntactic only; no registry call is made, no name availability is checked and no package is installed.

References & standards