Skip to content

Assignments to exported variables are not visible in other modules #38

@dennisjlee

Description

@dennisjlee

Expected Behavior

If a module exports a variable that was defined with let and can be reassigned, other modules that import that variable should always see the current value of the variable.

E.g.

env.js:

let env = { FOO: 'baz' };   // Starts with an old value

function setEnv(newEnv) {
  // Allow callers to set a new value
  env = newEnv;
}

export { env, setEnv };

If module1 calls setEnv with a new value, and module2 references env, module2 should see the new value.

Actual Behavior

With the Node flag --experimental-loader=import-in-the-middle/hook.mjs, module2 actually sees the old value.

Steps to Reproduce the Problem

I made a repro here: https://github.com/dennisjlee/iitm-assign-module-var-repro

Specifications

  • Version: import-in-the-middle 1.4.2
  • Platform: Node 18.18.2 or 20.9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions