Skip to content

Instantly share code, notes, and snippets.

@also
Created September 27, 2021 16:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save also/61a7066bf220e02deda9c9dec0bb6931 to your computer and use it in GitHub Desktop.
Save also/61a7066bf220e02deda9c9dec0bb6931 to your computer and use it in GitHub Desktop.

If the imports in entry.mjs are sorted, running node entry.mjs will fail with

node entry.mjs 
file:///Users/rberdeen/work/scratch/test-import-circular-order/b.mjs:5
export default { name, other: other.name };
                                    ^

ReferenceError: name is not defined
    at file:///Users/rberdeen/work/scratch/test-import-circular-order/b.mjs:5:37
    at ModuleJob.run (internal/modules/esm/module_job.js:152:23)
    at async Loader.import (internal/modules/esm/loader.js:177:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5)
import * as other from './b.mjs';
export const name = 'a';
export default () => ({ name, other: other.name });
import * as other from './a.mjs';
export const name = 'b';
export default { name, other: other.name };
// the order of these imports is important
import b from './b.mjs';
import a from './a.mjs';
console.log({ a: a(), b });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment