Language concepts

Circular module dependency

Try the free JavaScript compiler

A dependency graph contains a cycle when a module is reachable from itself. Linking supports cyclic source text modules, but early access to uninitialized lexical exports may fail. Multi-file example: save each listed file separately, then run the entry file with Node.js. See the packaged fixture for the original files.

Formal Syntax & Structure

javascript syntaxjavascript
A imports B; B imports A

Working Example

Example Snippetjavascript
// File: a.mjsimport { readA } from "./b.mjs";export const value = 7;export function result() { return readA() + 1; }
// File: b.mjsimport { value } from "./a.mjs";export function readA() { return value; }
// File: main.mjsimport { result } from "./a.mjs";console.log(result());
JavaScript Reference