JavaScript
CommonJS
AMD
RequireJS
Web Development

Relation between CommonJS, AMD and RequireJS?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

CommonJS, AMD, and RequireJS are related, but they are not interchangeable terms. Two of them describe module formats, while one of them is a loader that implements one of those formats.

The clean way to remember the relationship is this: CommonJS is a module specification, AMD is another module specification designed for browsers, and RequireJS is a popular implementation of AMD.

CommonJS and AMD Solve Similar Problems Differently

JavaScript originally had no standard module system, so projects invented conventions for splitting code into reusable files. CommonJS became popular on the server side, especially in Node.js. Its design assumes synchronous loading, which is fine when files are on local disk.

javascript
1// math.js
2function add(a, b) {
3  return a + b;
4}
5
6module.exports = { add };
javascript
// app.js
const math = require("./math");
console.log(math.add(2, 3));
text
5

AMD, short for Asynchronous Module Definition, was designed with browsers in mind. Browser scripts may need to fetch files over the network, so asynchronous loading is much more practical.

javascript
1// math.js
2define([], function () {
3  function add(a, b) {
4    return a + b;
5  }
6
7  return { add: add };
8});
javascript
1// app.js
2require(["math"], function (math) {
3  console.log(math.add(2, 3));
4});

The core difference is not just syntax. It is the loading model:

  • CommonJS typically loads dependencies synchronously
  • AMD defines modules so they can be loaded asynchronously

Where RequireJS Fits

RequireJS is not a third module format sitting beside CommonJS and AMD. It is a JavaScript library that loads modules in the browser and follows the AMD format.

That means:

  • AMD is the specification
  • RequireJS is one implementation of that specification

When you write define([...], function (...) { ... }) in an AMD-style browser project, RequireJS is often the tool interpreting that definition and resolving dependencies.

Here is a small RequireJS setup:

html
1<!doctype html>
2<html>
3  <head>
4    <script
5      data-main="app"
6      src="https://requirejs.org/docs/release/2.3.6/minified/require.js">
7    </script>
8  </head>
9  <body></body>
10</html>

With that in place, RequireJS loads app.js, reads its dependencies, and loads those files asynchronously.

Why These Systems Existed

Each system reflects the environment it was built for.

CommonJS worked well for early server-side JavaScript because reading files synchronously during startup was acceptable. AMD worked better in browsers where blocking the page while several script files download would hurt performance and user experience.

RequireJS became popular because it provided a practical browser loader with dependency management, path configuration, and optimization tooling.

Today, native ES modules cover much of this space, but you will still find CommonJS in Node.js codebases and AMD or RequireJS in older frontend applications and enterprise tools.

How to Think About Them Today

If you are maintaining older code, the most important distinction is conceptual:

  • CommonJS tells you how a module exports and imports values
  • AMD tells you how a module is defined for asynchronous loading
  • RequireJS is the runtime loader that makes AMD modules work in the browser

You may also encounter tools that translate between formats. Bundlers such as Webpack, Rollup, and Vite can often consume CommonJS and AMD inputs and produce modern bundles. That is why many teams no longer author new code directly in AMD even though old modules still run.

Common Pitfalls

  • Thinking RequireJS is a competitor to AMD. RequireJS implements AMD rather than replacing it.
  • Assuming CommonJS is ideal in the browser. Its synchronous loading model is one reason AMD existed.
  • Treating the syntax difference as the whole story. The real difference is when and how dependencies are loaded.
  • Ignoring ES modules when starting a new project. For modern code, native import and export are usually the better choice.

Summary

  • CommonJS and AMD are module definitions, not the same kind of thing as RequireJS.
  • CommonJS is associated with synchronous loading and server-side JavaScript.
  • AMD was designed for asynchronous browser loading.
  • RequireJS is a loader that implements AMD.
  • Modern projects usually prefer ES modules, but understanding these older systems is still useful when maintaining legacy code.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.