Reputation: 707
I made an export Javascript file like following:
export const A = 1;
export const B = 2;
export const C = 3;
And, I try to import that to another Javascript file like following:
import 'path/export_file.js'
console.log(A); // ReferenceError: A is not defined
I know I can fix it if I do the following:
import A from 'path/export_file.js'
// or
import { A, B, C } from 'path/export_file.js'
But I want to use like import 'path/export_file.js'
Some modules just do import'path/file'
and I can use all of exported from that module.
What should I do?
Or am I mistaken for something?
Upvotes: 0
Views: 87
Reputation:
There are 2 things to know:
You should know about Import/Export default & named in ES6
As @CertainPerformance's mention, you have to use {} unless the module assigns to global properties.
import { A, B, C } from 'path/export_file.js
In case of mix both Default
and Named
, you can use *
like this
import * as Mix from 'path/export_file.js
Thanks @prosti's answer with a great answer.
Upvotes: 3