Skip to main content

Normalize Modules

Normalize exports, main, type, browser, and imports fields in workspace package.json files.

Summary

The normalize-modules recipe ensures that module resolution fields in each workspace's package.json follow the official Node.js module specification conventions.

It handles exports map structure, main entry point, module type declaration, browser field, and import maps.

Why Use This Command?

  1. Keeps Node.js entry points aligned with the module fields each workspace role supports.
  2. Normalizes shorthand exports into one predictable object shape and keeps explicit conditions reachable.
  3. Removes inapplicable module fields before they advertise entry points that should not exist.

Requirements

  • Node.js runtime — Use a supported Node.js LTS release with the Nova CLI available.
  • Project config — Register the workspace and enable recipes.package-json.<workspace>.normalize-modules in nova.config.json.
  • Workspace manifest — The configured workspace must contain a readable package.json file.

Behavior

For each eligible workspace, the recipe inspects module resolution fields and applies the following rules. See Workspace Rules for how tags are determined.

  • exports (Conditional) — Removed if the workspace role is not config, package, or tool. For allowed roles, a string value is normalized into { ".": { "default": value } }, and a string at exports['.'] becomes { "default": value }. If an explicit exports['.'] condition map puts default before other conditions, the recipe moves default last so those conditions remain reachable. It never invents require or browser conditions; declare them explicitly when the package actually provides those entry points.
  • main (Conditional) — Removed if the workspace role is not config, app, package, or tool. Otherwise preserved independently: main is a legacy fallback entry point for either module format, not a synonym for exports['.'].require. When exports is defined, Node.js uses it in preference to main for supported imports.
  • type (Conditional) — Removed if the workspace role is not config, app, package, or tool.
  • browser (Conditional) — Removed if the workspace role is not package. Otherwise preserved independently of any explicit exports['.'].browser condition.
  • imports (Conditional) — Removed if the workspace role is not config, app, package, or tool.

Usage

Options

FlagDescription
-d, --dry-runRun without writing any files.
-r, --replace-fileOverwrite the original file instead of creating a .nova-backup copy.