ES6 import equivalent of require() without exports

Javascriptnode.jsEcmascript 6RequireJavascript Import

Javascript Problem Overview


By using require(./filename) I can include and execute the code inside filename without any export defined inside filename itself.

What is the equivalent in ES6 using import ?

Thanks

Javascript Solutions


Solution 1 - Javascript

The equivalent is simply:

import "./filename";

Here are some of the possible syntax variations:

import defaultMember from "module-name";  

import * as name from "module-name";  

import { member } from "module-name";  

import { member as alias } from "module-name";  

import { member1 , member2 } from "module-name";  

import { member1 , member2 as alias2 , [...] } from "module-name";  

import defaultMember, { member [ , [...] ] } from "module-name";  

import defaultMember, * as name from "module-name";  

import "module-name";

SOURCE: MDN

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncrashView Question on Stackoverflow
Solution 1 - JavascriptCodingIntrigueView Answer on Stackoverflow