RequireJS is a foundational JavaScript file and module loader, primarily designed for asynchronous module definition (AMD) in web browsers, which was crucial for managing dependencies and organizing code before native ES Modules (ESM) were widely adopted. The `requirejs` npm package provides a Node.js adapter, `r.js`, which serves as both an AMD runtime for server-side execution and a powerful optimizer for bundling and minifying browser-side AMD modules. Its current stable version is 2.3.8, last published in November 2025. While it has received infrequent updates for critical fixes (e.g., a prototype pollution vulnerability fix in 2.3.7), its lead maintainer has indicated it's in "end of life mode" for new feature development. RequireJS differentiates itself by offering a consistent module format across browser and Node environments, simplifying build processes for complex web applications. However, its relevance has significantly diminished with the pervasive support for ES Modules in modern JavaScript ecosystems, which offer more efficient loading and static analysis capabilities without needing a separate loader or optimizer in many scenarios.
npm install requirejsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use the `requirejs` npm package in Node.js to load a simple AMD module and programmatically run the `r.js` optimizer to bundle modules.
For new projects, consider using native ES Modules (`import`/`export`) or CommonJS (`require`/`module.exports`) depending on your target environment and existing codebase. Modern bundlers like Webpack, Rollup, or Vite can handle ESM efficiently.
When initializing RequireJS in Node, pass Node's `require` function to the `nodeRequire` configuration option: `requirejs.config({ nodeRequire: require });` This allows RequireJS to fall back to Node's module loader if an AMD module is not found.Upgrade to RequireJS version 2.3.8 or later to mitigate the prototype pollution vulnerability. If an upgrade is not immediately possible, apply a global shim to prevent prototype pollution.
Ensure all module paths in your build configuration are relative to the `baseUrl` or `mainConfigFile` and point to local files. If you have external dependencies, configure them as module names and map them to local files or use a different build strategy for those parts.
Avoid using `shim` configuration when running RequireJS within a Node.js environment. If you need to include non-AMD libraries, consider using a separate CommonJS-compatible version if available, or isolate their usage to the browser build. RequireJS will log a warning about `shim` config in Node, which can be suppressed with `requirejs.config({ suppress: { nodeShim: true }});`.Ensure each AMD module file contains only one top-level `define()` call. For optimized builds, consider using the optimizer's naming conventions or ensuring `name` configuration is correct to prevent anonymous modules from clashing.
Check the module's path in your `requirejs.config({ paths: ... })`. Verify the file exists and is accessible. Inspect browser developer tools (Network tab) for 404 errors or console for script errors in the module. Increase `waitSeconds` in `requirejs.config` if the script legitimately takes longer to load (e.g., `waitSeconds: 200`).In browsers, ensure `require.js` is loaded via a `<script>` tag before any AMD modules, and use its `require()` or `define()` for modules. In Node.js, use `const module = require('module');` for CommonJS modules, and the `requirejs` package's configured instance for AMD modules.Inspect your browser's console or Node.js terminal for the full stack trace. The error message should point to the file and line number where the issue originated, indicating a bug within your module's logic.
No dependency data recorded yet.