I'm using ES6 modules and am importing a variable from moduleA
into moduleB
:
//moduleA.js
let a = 5;
let b;
export { a, b };
//moduleB.js
import { a, b } from './moduleA'
a = 6;
b = 1;
But on change/assignment in moduleB
I'm getting error such as:
a = 6;
ReferenceError: a is not defined
On the other hand I can console.log(a)
in moduleB
.
It seems it is not possible to assign to imported variables? Is this true or am I missing the way to do it? Why is this not possible?