Files look like this:
-test
--index.js
--test1.js
--test2.js
test1.js:
export const val1 = "TEST 1";
export const val2 = "TEST 2";
export const val3 = "TEST 3";
export const val4 = "TEST 4";
test2.js:
export const val5 = "TEST 5";
export const val6 = "TEST 6";
export const val7 = "TEST 7";
export const val8 = "TEST 8";
index.js:
import * as test1 from "./test1";
import * as test2 from "./test2";
export default { ...test1, ...test2 };
In another file:
import { val6 } from "./test";
The variable var6
is undefined.
However if I do this:
import test from "./test";
const { val6 } = test;
then var6 is defined and is equal to "TEST 6".
The test1 and test2 objects have the key __esModule: true
.
I don't understand why this is the case. Why is var6 undefined in the first example?