Module Import or Store Initialization Bug: Duplicate Initialization
# Problem
When running with `llrt`, the store is initialized twice and imports within submodules do not share the same instance of the store, leading to `undefined` when using functions from a nested module. This diverges from expected ECMAScript module semantics.
This issue could point to a problem with module caching and singletons for ESM, where separate module loads result in duplicate state.
Environment
- LLRT v0.8.1-beta (darwin, arm64)
## Expected
```bash
$ llrt index.js
store initialized
get bar
get_in_bar bar
```
## Actual
```bash
$ llrt index.js
store initialized
store initialized
get bar
get_in_bar undefined
```
## Example
**Directory Structure:**
```
.
├── index.js
└── lib
├── bar
│ └── index.js
└── shared
└── store.js
```
**index.js**
```js
import { get, set } from './lib/shared/store.js';
import { get_in_bar } from './lib/bar/index.js';
set('foo', 'bar');
console.log('get', get('foo')); // Output: 'bar'
console.log('get_in_bar', get_in_bar('foo')); // Output: 'bar'
```
**lib/shared/store.js**
```js
const store = {};
console.log('store initialized');
export function set(key, value) {
store[key] = value;
}
export function get(key) {
return store[key];
}
```
**lib/bar/index.js**
```js
import { get } from '../shared/store.js';
export function get_in_bar(key) {
return get(key);
}
```
0 条评论