Package boundaries, versions and bundling
How it works
A module is a unit of code; a package groups modules and metadata. Node uses package.json fields such as type and exports to interpret and expose package entry points. Dependency ranges express accepted versions; a lockfile records the selected resolution for reproducible installation in a particular package manager. A bundler can combine modules, split chunks and remove some unused code, but side effects and dynamic dependencies limit these optimizations. Package metadata is not ECMAScript grammar.
Example 1
Save each file separately. Run with Node.js: main.js. This is a multi-file example, not a single editor snippet.
package.json
{ "type": "module", "name": "local-pricing", "version": "1.0.0", "exports": "./price.js"}price.js
main.js
Expected output in the tested environment:
15Node resolves the package self-reference through its exports entry; type marks .js files as ESM.
Common mistake
Tree shaking does not guarantee that every unused-looking statement disappears. A module may have observable effects at evaluation time.
Practice
Draw public and private module boundaries for a small pricing package. Add an internal helper that is not exposed through exports.
Run this practice in the documented local environment. ByteMind module and asynchronous grader support is not yet verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Package boundaries, versions and bundling — Knowledge Check
Reason about the concept and predict its behavior in the indicated environment.
What does the type field in this package fixture control?
What is the purpose of a dependency lockfile?
Why can a bundler retain apparently unused module code?
Which package field restricts public entry point resolution in the displayed Node fixture?
For Package boundaries, versions and bundling, what is the console output of example 1 in Node.js 22.16.0?
// File: package.json{"type":"module","name":"local-pricing","version":"1.0.0","exports":"./price.js"}
// File: price.jsexport const price = n => n * 5;
// File: main.jsimport { price } from "local-pricing";console.log(price(3));