package.json Generator
Scaffold a modern package.json with exports, scripts, engines and validation.
Package fields
11 fieldspackage.json
27 lines · 474 chars{
"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
name my-lib, type module, exports . → dist/index.js"exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" } }Conditional exports give modern bundlers the right artifact while preserving type resolution.
CLI package
bin mycli → ./bin/cli.js"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
>=20 <23"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
Start from a template
Choose ESM library, CLI, Node app or TypeScript package to seed sensible defaults.
Fill identity and entry points
Set name, version, type, main/module/types and an exports map for the public subpaths.
Add scripts and dependencies
Use add-row controls for scripts and name@range dependency entries; duplicates are merged deterministically.
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
| Order | Key |
|---|---|
| 1 | name, version, description, private |
| 2 | type, main, module, types, exports, bin, files, sideEffects |
| 3 | scripts, engines, packageManager |
| 4 | keywords, author, license |
| 5 | dependencies, 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
Related tools
ABA Routing Number Generator
Generate 9-digit US ABA routing numbers with weighted Mod-10 checks.
Address Generator
Generate realistic addresses in the correct format for 21 countries — single-line, multi-line, JSON or HTML — plus a postcode validator. Test data only, runs in your browser.
API Key Generator
Generate realistic test API keys — custom prefixes, lengths, alphabets, optional checksum, bulk .env/CSV export. Locally in your browser.
Argentina CUIT / CUIL Generator
Generate and validate 11-digit Argentine CUIT and CUIL numbers with AFIP Mod-11 check digits.
ASCII Text Art Generator
Turn text into large ASCII art banners with multiple figlet fonts
Australia ABN Generator
Generate and validate 11-digit Australian Business Numbers (ABN) using weighted Mod-89.