Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
monopack (global installation)
✓ monopack <command>
✗ require('monopack')
This package is a CLI tool and not intended for programmatic import. Use 'yarn global add monopack' or 'npm install -g monopack' to install globally.
monopack (local installation via Yarn)
✓ yarn run monopack <command>
✗ monopack <command>
After installing locally with 'yarn add -D monopack', invoke through Yarn's run script mechanism.
monopack (local installation via npm)
✓ ./node_modules/.bin/monopack <command>
✗ monopack <command>
After installing locally with 'npm install --save-dev monopack', invoke directly from the local bin directory.
This example demonstrates how to set up a minimal mock Node.js monorepo project and use `monopack build` to bundle an application, including a locally linked shared library and a third-party dependency, into a static deliverable. It then executes the resulting bundle.
import { execSync } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
// Create a temporary directory for the mock monorepo
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'monopack-demo-'));
const appPackageDir = path.join(tempDir, 'packages', 'my-app');
const sharedLibDir = path.join(tempDir, 'packages', 'shared-lib');
console.log(`Setting up mock monorepo in: ${tempDir}`);
// Create application package structure
fs.mkdirSync(path.join(appPackageDir, 'src'), { recursive: true });
fs.writeFileSync(path.join(appPackageDir, 'package.json'), JSON.stringify({
name: 'my-app',
version: '1.0.0',
main: 'src/main.js',
dependencies: {
'lodash': '^4.17.21' // Third-party dependency
}
}, null, 2));
fs.writeFileSync(path.join(appPackageDir, 'src', 'main.js'), `
const _ = require('lodash');
const { getMessage } = require('shared-lib'); // Monorepo dependency
console.log(_.toUpper(getMessage('Monopack Demo')));
`);
// Create shared library package structure
fs.mkdirSync(sharedLibDir, { recursive: true });
fs.writeFileSync(path.join(sharedLibDir, 'package.json'), JSON.stringify({
name: 'shared-lib',
version: '1.0.0',
main: 'index.js'
}, null, 2));
fs.writeFileSync(path.join(sharedLibDir, 'index.js'), `
exports.getMessage = (topic) => 'Hello from shared-lib, ' + topic + '!';
`);
// Simulate monorepo setup with yarn and install local monopack
try {
console.log('\nInstalling dependencies and linking shared-lib...');
execSync(`cd ${appPackageDir} && yarn add file:${sharedLibDir}`, { stdio: 'inherit' });
execSync(`cd ${appPackageDir} && yarn install`, { stdio: 'inherit' });
execSync(`cd ${appPackageDir} && yarn add -D monopack-cli@0.2.6`, { stdio: 'inherit' });
console.log('\n--- Running monopack build ---');
const outputDir = path.join(appPackageDir, 'dist');
// Execute monopack locally using its path in node_modules
execSync(`cd ${appPackageDir} && ./node_modules/.bin/monopack build src/main.js --out-dir ${outputDir}`, { stdio: 'inherit' });
console.log(`\nBuild successful. Output directory contents for 'my-app': ${outputDir}`);
console.log(fs.readdirSync(outputDir));
console.log('\n--- Running the bundled application ---');
// To run the bundled application, it usually requires its own node_modules
// which monopack should have generated in the output directory.
execSync(`cd ${outputDir} && node main.js`, { stdio: 'inherit' });
} catch (error: any) {
console.error('\nAn error occurred during the quickstart execution:', error.message);
if (error.stdout) console.error('stdout:', error.stdout.toString());
if (error.stderr) console.error('stderr:', error.stderr.toString());
} finally {
console.log(`\nCleaning up temporary directory: ${tempDir}`);
fs.rmSync(tempDir, { recursive: true, force: true });
}
monopack --version
Errors
Common errors & fixes
Error: Cannot find module 'some-dynamically-required-module'
Monopack's static analysis may not detect modules that are dynamically required at runtime (e.g., certain database drivers or plugins).
fixUse the `--with-extra-module <module-name>` CLI option to explicitly include such dependencies. For example: `monopack build main.js -m mysql`.
command not found: monopack
The `monopack` command is not accessible in your system's PATH. This typically happens if it's not installed globally, or if installed locally, it's not being invoked correctly.
fixIf installed globally, ensure your global npm/yarn bin directory is in your PATH. If installed locally, invoke it via `yarn run monopack <command>` (if configured in `package.json` scripts) or `./node_modules/.bin/monopack <command>`.
Audit
Dependencies
noderequiredRuntime environment. Requires Node.js >= 6.14.4.
yarnrequiredRequired for deterministic dependency installation and consistent builds. Requires Yarn >= 1.3.2.