Home > Engineering > Bare Runtime > Module System
Module resolution and loading in Bare, powered by bare-module.
.cjs, or .js when "type" is not
"module").mjs, or .js when
"type": "module").json).bundle — bare-bundle format).node)CJS and ESM have bidirectional interoperability — unlike Node.js where the relationship is one-way.
Supports subpath exports, conditional exports, self-referencing, and sugar syntax.
{
"exports": {
".": {
"bare": "./lib/bare.js",
"default": "./lib/node.js"
},
"./promises": "./lib/promises.js"
}
}
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": {
"bare": ">=1.0.5"
}
}
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.
require(specifier[, options]) — load module.
Options include { with: { type: 'json' } } and
{ with: { imports: '...' } }require.main — entry modulerequire.cache — module cacherequire.resolve(specifier[, parentURL]) —
resolve to pathrequire.addon([specifier][, parentURL]) — load
native addonrequire.addon.host — platform-arch stringrequire.addon.resolve() — resolve addon pathrequire.asset(specifier[, parentURL]) — resolve
asset pathimport.meta.url — module URL stringimport.meta.main — boolean, is entry script?import.meta.cache — module cacheimport.meta.resolve(specifier[, parentURL]) —
resolve to URL stringimport.meta.addon() — load native addonimport.meta.asset(specifier[, parentURL]) —
resolve asset URLModule.createRequire(parentURL[, options])
Create a preconfigured require function. Useful for REPL, tooling, or custom loaders.
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.