The World of Splectrum

Home > Engineering > Bare Runtime > Module System

Bare Module System

Module resolution and loading in Bare, powered by bare-module.


Supported Module Types

CJS and ESM have bidirectional interoperability — unlike Node.js where the relationship is one-way.


Package.json Fields

“exports” — entry points

Supports subpath exports, conditional exports, self-referencing, and sugar syntax.

{
  "exports": {
    ".": {
      "bare": "./lib/bare.js",
      "default": "./lib/node.js"
    },
    "./promises": "./lib/promises.js"
  }
}

“imports” — private import mapping

Maps import specifiers within the package. Supports conditional syntax. Permits mapping to external packages. The # prefix is supported but not required (unlike Node.js).

{
  "imports": {
    "fs": {
      "bare": "bare-fs",
      "default": "fs"
    }
  }
}

“engines” — version requirements

{
  "engines": {
    "bare": ">=1.0.5"
  }
}

Conditional Export Conditions

In order of specificity (most specific first):

Condition Matches when
"import" loaded via import or import()
"require" loaded via require()
"asset" loaded via require.asset()
"addon" loaded via require.addon()
"bare" running in Bare
"node" running in Node.js
"<platform>" equals Bare.platform
"<arch>" equals Bare.arch
"simulator" compiled for simulator
"default" fallback, always matches

Order matters: more specific conditions must come before less specific ones in the definition.


CJS API

ESM API

Custom require

Module.createRequire(parentURL[, options])

Create a preconfigured require function. Useful for REPL, tooling, or custom loaders.


Custom Protocols

Module resolution can be extended with custom protocols — for example, loading modules from a Hyperdrive:

new Module.Protocol(methods, context)

Methods: preresolve, postresolve, resolve, exists, read, addon, asset.


Source: https://github.com/holepunchto/bare-module


© 2026 In Wonder - The World of Splectrum, Jules ten Bos. The conversation lives at In Wonder - The Conversation.