nodejs / nodejs/import-in-the-middle

Assignments to exported variables are not visible in other modules

Open
#38 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
170
Forks
58
Avg merge
3d 19h
Merged PRs (30d)
7

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the linked reproduction with Node 18.18.2 or 20.9.0 and the --experimental-loader=import-in-the-middle/hook.mjs flag. Read hook.mjs and the module-loading path it invokes, then verify that an imported, reassigned let binding is observed with its current value rather than its initial value.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.