package.json Generator and Validator
Fill in a form to get a clean package.json for a library, CLI or app, or paste yours to see errors, warnings and tips before you publish to npm.
Berjalan dalam pelayar anda. Fail anda tidak pernah meninggalkan peranti. Lihat cara menyemaknya
…
Cara melakukannya
- 1Choose a mode
Use Build package.json to start from a form, or Check an existing file to open or paste one.
- 2Fill in the basics
Enter name, version, licence, description, author and links; the repository is normalised to the git+https form.
- 3Set entry points
Pick the module type, main and types, then apply an exports preset and edit it as JSON.
- 4Add scripts and commands
Start from a script preset or add your own rows, and list any bin commands for a CLI.
- 5Add dependencies
Paste name@range lines in bulk, choose the group, and fix anything the checks flag.
- 6Download
Copy package.json or download it, after the checks panel shows no errors.
Tentang alat ini
package.json looks simple, yet small mistakes in it cause some of the most confusing problems in the JavaScript ecosystem: a package that installs but cannot be imported, TypeScript that cannot find the types, a CLI that does nothing, or a publish that npm rejects. This tool has two halves. The builder is a form with every field most projects need: name, version, description, author, keywords, license, repository, homepage and bugs; type, main, module and types; an exports editor with presets for dual ESM and CommonJS, ESM only, CommonJS only and subpath patterns; scripts with presets for a TypeScript library, a Node CLI, a Vite app and a Next.js app; bin commands; files, sideEffects, engines, packageManager and publishConfig; and four dependency groups with a bulk box where you paste name@range lines. The JSON is written in the conventional field order with dependencies sorted alphabetically, exactly as npm itself would write them. The checker runs on the built file and on any package.json you open or paste. It applies the npm package name rules (lowercase, URL-safe, 214 characters, no leading dot or underscore, no Node core module names, correct scope syntax), validates the version as semver 2.0, parses every dependency range, recognises workspace, file, git, npm alias and URL specifiers, and checks the exports map: targets must start with ./, types must come first, default must come last, and subpaths cannot be mixed with conditions. It also flags install scripts, deprecated prepublish, shell-only commands, wide-open ranges, local paths in published packages, packages listed twice, and tools that belong in devDependencies.
Errors, warnings and tips
Errors are problems npm, Node.js or TypeScript will act on: an invalid name or version, an exports target without ./ or an engines range that does not parse. Warnings are legal but risky, such as a dependency on * or a deprecated SPDX licence id. Tips point out conventions, for example that a library without a files list publishes its tests too.
The exports field in practice
Once exports is present, Node.js only lets people import the paths listed in it, so remember ./package.json if tools read it. Conditions are matched from top to bottom and the first match wins, which is why types must be first and default last. A dual package needs separate files for import and require, usually .js and .cjs when type is module.
Loading an existing file
Load into the form copies the known fields into the builder so you can fix them with undo and redo. Fields the form does not cover, such as workspaces, overrides or browserslist, are listed so you can add them back by hand.
Limits
Versions are not looked up on the npm registry, so the tool cannot tell whether a version exists or is the latest; it only checks that the range is valid. It is not a replacement for npm publish --dry-run, which also shows the exact file list.
Contoh berselesaian
A pasted file has the name My-Utils, version 1.0, license GPL-3.0, type esm, typescript and eslint in dependencies, lodash in both dependencies and devDependencies, a postinstall script and engines.node set to sixteen. The checker reports 4 errors (name must be lowercase, version is not semver, type must be module or commonjs, engines.node is not a range), 3 warnings (deprecated GPL-3.0 id, install script, lodash listed twice) and tips to move typescript and eslint to devDependencies. After Load into the form and five edits, the rebuilt file has 0 errors.
Ringkasnya
- Kategori: Pembangun & data
- Berjalan dalam pelayar, tanpa pendaftaran, tanpa muat naik.
- Maklumat yang anda masukkan kekal pada peranti anda.
- Tersedia dalam bahasa Inggeris.
- Kandungan disemak kali terakhir:
- Sumber rasmi: npm Docs, package.json reference
Soalan lazim
Can it create a package.json for an app that is never published?
Yes. Tick private and the checker relaxes the rules that only matter for publishing, such as a required name, version and licence, and it stops warning about local file: dependencies.
Which licence should I pick?
MIT and ISC are the most common permissive choices for JavaScript libraries, and Apache-2.0 adds an explicit patent grant. Use UNLICENSED for private code you do not want others to use. For GPL licences the SPDX ids now end in -only or -or-later.
Does it check that dependency versions exist?
No. Nothing is sent to the npm registry. The checker validates the syntax of each range and flags risky ones such as *, latest and empty strings, but it cannot tell you whether 4.17.99 was ever published.
Why does the order of conditions in exports matter?
Node.js and bundlers walk the conditions in the order written and use the first one that applies. If default comes before import, the import line is never reached, and TypeScript only reads types when it appears before the other conditions.
What does the files field do?
It is an allow-list of files and folders included when you run npm publish. package.json, README and LICENSE are always included. Without files, everything not excluded by .npmignore or .gitignore is published, which often includes tests and source maps.
Is my package.json uploaded?
No. The form, the checks and the file you open stay in your browser. The draft is saved in this browser's local storage so you can come back to it.
