LogoPear Docs
ReferencesBareModules

bare-module

Reference for bare-module: Bare's module system—CommonJS and ESM resolution, loading, and the require / import.meta surfaces.

stable

bare-module implements Bare's module system: CommonJS and ESM with bidirectional interop, native-addon and asset resolution, and the require / import.meta surfaces. It's the machinery behind bare's Module.load(). It's a native addon and requires Bare >=1.23.0 <1.29.0.

npm i bare-module

Usage

const Module = require('bare-module')

API

Module

const url = Module.resolve(specifier, parentURL[, options]) · Module.asset(specifier, parentURL[, options])

Resolve a module or asset specifier to a URL.

const module = Module.load(url[, source][, options])

Load (and cache) a module. The returned module exposes url, filename, dirname, type, defaultType, cache, main, exports, imports, resolutions, builtins, conditions, and protocol.

Module.constants · Module.protocol · Module.cache

Module state/type constants, the protocol table, and the global module cache.

require

require(specifier[, options]) plus require.main, require.cache, require.resolve(specifier[, parentURL]), require.addon([specifier][, parentURL]) (with require.addon.host and require.addon.resolve(...)), and require.asset(specifier[, parentURL]).

import / import.meta

Static and dynamic import (including import attributes, for example with { type: 'json' }), plus import.meta.url, import.meta.main, import.meta.cache, import.meta.dirname, import.meta.filename, import.meta.resolve(specifier[, parentURL]), and import.meta.addon([specifier][, parentURL]).

Builds on bare-module-resolve, bare-module-lexer, bare-bundle, bare-path, and bare-url.

See also

On this page