Package.json Validation

Complete package.json validation setup

Package.json Validation

Packem validates your package.json to make sure the fields needed to publish a working package are configured correctly. This example shows the full validation.packageJson shape and what each toggle controls.

Overview

This example demonstrates:

  • Enabling validation for individual package.json fields
  • Allowing custom export conditions and extra export extensions
  • Turning specific checks on or off

Configuration

// packem.config.ts
import { defineConfig } from '@visulima/packem/config'
import transformer from '@visulima/packem/transformer/esbuild'

export default defineConfig({
    transformer,
    validation: {
        packageJson: {
            // Validate individual fields
            name: true,
            main: true,
            module: true,
            types: true,
            typesVersions: true,
            exports: true,
            files: true,
            bin: true,
            dependencies: true,
            engines: true,
            sideEffects: true,

            // Allow custom export conditions without warnings
            extraConditions: ["custom-bundler", "my-framework"],

            // Allow extra file extensions in the exports field
            allowedExportExtensions: [".css", ".wasm"],
        },
    },
})

Available checks

Every field below is an individual boolean toggle under validation.packageJson:

OptionDescription
nameValidate the name field
mainValidate the main field
moduleValidate the module field
typesValidate the types field
typesVersionsValidate the typesVersions field
exportsValidate the exports field
filesValidate the files field
binValidate the bin field
dependenciesValidate dependencies
enginesValidate the engines field
sideEffectsValidate the sideEffects field
extraConditionsstring[] of extra export conditions to treat as valid
allowedExportExtensionsstring[] of additional file extensions allowed in exports

What this does

  • Packem checks that the enabled fields exist and point at files the build actually produces.
  • exports validation flags unknown export conditions. Add custom ones to extraConditions so they don't warn (see the Extra Conditions example).
  • allowedExportExtensions lets non-JS outputs (such as .css or .wasm) appear in exports without triggering an "unexpected extension" warning.

Disabling a specific check

Set any field toggle to false to skip just that check while keeping the rest:

validation: {
    packageJson: {
        // Validate everything except the engines field
        name: true,
        main: true,
        types: true,
        exports: true,
        engines: false,
    },
}

Disabling all validation

To turn off every validator (package.json, bundle size, and dependencies) set validation to false:

export default defineConfig({
    transformer,
    validation: false,
})

You can also pass --no-validation on the CLI:

packem build --no-validation
Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues