{"id":11089,"library":"install","title":"Install.js CommonJS Module Loader for Browsers","description":"Install.js is a minimal JavaScript module loader designed primarily to deliver CommonJS modules to web browsers, addressing the challenge of synchronous `require` semantics in a browser environment. While it provides a feature-rich, small-footprint solution for its original purpose, its development has been inactive since its last update in 2018 (version 0.13.0). The package offers explicit control over module installation and resolution, including options for file extensions, package.json `mainFields`, and a `fallback` mechanism for unresolved modules. It was created in an era before modern bundlers (like Webpack, Rollup) and native ECMAScript Modules (ESM) became standard practice, making its direct use in new projects less common today.","status":"abandoned","version":"0.13.0","language":"javascript","source_language":"en","source_url":"git://github.com/benjamn/install","tags":["javascript","modules","require","commonjs","exports","browser","packaging","packager","install"],"install":[{"cmd":"npm install install","lang":"bash","label":"npm"},{"cmd":"yarn add install","lang":"bash","label":"yarn"},{"cmd":"pnpm add install","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-first. ESM `import` syntax is not directly supported without a transpiler or bundler.","wrong":"import { makeInstaller } from 'install';","symbol":"makeInstaller","correct":"const install = require('install').makeInstaller;"},{"note":"The primary `install` function is the *return value* of `makeInstaller`, not directly exported by the package.","wrong":"const installFn = require('install');","symbol":"install","correct":"const installFn = require('install').makeInstaller({...});"},{"note":"The `require` function within installed modules is local to the `install` function's context, not the global Node.js `require` or browser global. Be careful not to overwrite the global `require` in Node.js.","wrong":"require('./my-module');","symbol":"require (from installed modules)","correct":"const localRequire = installFn({...}); localRequire('./my-module');"}],"quickstart":{"code":"const makeInstaller = require('install').makeInstaller;\n\n// Step 1: Create an install function with optional configurations\nconst install = makeInstaller({\n  extensions: [\".js\", \".json\"],\n  // fallback: (id) => { /* custom resolution logic, e.g., native Node.js require */ },\n  browser: typeof window !== 'undefined',\n  mainFields: [\"browser\", \"main\"]\n});\n\n// Step 2: Install modules using a nested object tree\nconst localRequire = install({\n  \"main.js\"(require, exports, module) {\n    const assert = require(\"assert\"); // Example: requiring a module within the installed context\n\n    assert.strictEqual(\n      require(\"package\").name,\n      \"/node_modules/package/entry.js\"\n    );\n\n    exports.name = module.id;\n  },\n\n  node_modules: {\n    package: {\n      \"package.json\"(require, exports, module) {\n        exports.name = \"package\";\n        exports.version = \"0.1.0\";\n        exports.main = \"entry.js\";\n      },\n      \"entry.js\"(require, exports, module) {\n        exports.name = module.id;\n      }\n    }\n  }\n});\n\n// Step 3: Require the entry point module(s) to evaluate them\nconsole.log(localRequire(\"./main\").name);\n// Expected output: \"/main.js\"","lang":"javascript","description":"This quickstart demonstrates how to initialize the `install` module loader, define and install custom CommonJS modules, and then `require` them using the loader's context. It shows the three main steps: `makeInstaller`, `install`, and `require`."},"warnings":[{"fix":"For new projects, consider modern bundlers for CommonJS/ESM compatibility or use native ESM. For legacy CommonJS in browsers, evaluate if a bundler could simplify the build process.","message":"The package's primary purpose—loading CommonJS modules directly in browsers—has been largely superseded by modern JavaScript bundlers (Webpack, Rollup, Parcel) and native ECMAScript Modules (ESM). Using `install` in new projects may introduce unnecessary complexity or reliance on an older module paradigm.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Always assign the result of `install()` to a locally scoped variable (e.g., `const myRequire = install(...)`) to avoid conflicts with Node.js's native module system.","message":"In a Node.js environment, the `install` package creates its own `require` context. Directly assigning the result of `install()` to a global `require` variable (e.g., `require = install(...)`) can overwrite Node.js's native `require` function, leading to unexpected behavior or breakage for built-in modules.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Assess the necessity of this package. If possible, migrate to actively maintained alternatives or modern bundling solutions that are compatible with CommonJS for long-term project health.","message":"The package has not seen updates since 2018 (version 0.13.0). This indicates it is no longer actively maintained. Relying on it for critical applications might pose long-term maintenance or security risks, as it may not receive updates for new JavaScript features, bug fixes, or security vulnerabilities.","severity":"gotcha","affected_versions":">=0.13.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure `install.js` (or a bundled version) is correctly loaded in your HTML, and that `makeInstaller` and the subsequent `install` calls have been executed to create the `require` function for your modules.","cause":"Attempting to use `require` in a browser environment without `install.js` being loaded and initialized, or before the `makeInstaller` and `install` steps have provided a local `require` function. CommonJS `require` is not native to browsers.","error":"ReferenceError: require is not defined"},{"fix":"Verify the module identifier path is correct relative to the calling module. Ensure the module is present in the object tree passed to `install`. Check `makeInstaller` options, especially `extensions` for implicit file endings and `mainFields` for `package.json` resolution.","cause":"This error occurs when the `install` loader cannot resolve a module identifier. This could be due to an incorrect path, the module not being explicitly 'installed' via the `install` function's object tree, or misconfiguration of `extensions` or `mainFields` in `makeInstaller`.","error":"Error: Cannot find module 'some-module'"},{"fix":"This package is designed for CommonJS. If you are in an ESM context, you would typically use a bundler (like Webpack) that understands both CJS and ESM to integrate modules handled by `install`. If sticking to `install`, use `require()` within its defined module contexts.","cause":"The `install` package implements a CommonJS-like module system. While it uses `exports` and `module.exports`, these are not directly compatible with native ECMAScript `import` statements without an intermediate bundling or transpilation step.","error":"module.exports = ... or exports.property = ... is not working as expected with `import` statements."}],"ecosystem":"npm"}