Skip to content

Instantly share code, notes, and snippets.

@also
Created September 27, 2021 16:29

Revisions

  1. also renamed this gist Sep 27, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. also created this gist Sep 27, 2021.
    14 changes: 14 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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)
    ```
    5 changes: 5 additions & 0 deletions a.mjs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    import * as other from './b.mjs';

    export const name = 'a';

    export default () => ({ name, other: other.name });
    5 changes: 5 additions & 0 deletions b,mjs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    import * as other from './a.mjs';

    export const name = 'b';

    export default { name, other: other.name };
    5 changes: 5 additions & 0 deletions entry.mjs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    // the order of these imports is important
    import b from './b.mjs';
    import a from './a.mjs';

    console.log({ a: a(), b });