ES6 import equivalent of require() without exports

crash :

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

CodingIntrigue :

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Import/ Exports in ES6

ES6 - Convert from 'require' to 'import'

What is the equivalent of module.exports for ES6 Modules?

Is ES6 `export class A` equivalent to `module.exports = A`?

What is ES6 equivalent of module.exports = { key: "value" }?

ES6 import alias SOME exports not ALL

ES6 equivalent of Node.js require function call

Jest mocking default exports - require vs import

Javascript ES6 import without a name

Import with or without curly brackets in ES6

Require syntax equivalent of Import in Nodejs

Add a module in in ES6 using import instead of require

Is it possible to require or import resource from cdn in javascript or es6

Correct way to translate ES6 "import" to nodejs "require"

How does 'require' operates differently from 'import' es6?

CommonJS require vs. ES6 import discrepancy

Convert from require to import es6 module

Cannot import npm modules after converting ES5 require to ES6 import

ES6 - is there an elegant way to import all named exports but not the default export?

require() equivalent if import { Something } from 'somewhere'

Convert require() without assignment to import

Export and import classes in React without ES6

How to import class using ES6 syntax? (without Babel)

Use ES6 'import' statement without transpilers

Difference between import a module with and without ".js" in es6 module

Is there any one-line analogy in ES6 for ES5 `module.exports = require('./inner.js')`?

How to export ES6 class in Javascript without module.exports

Import CommonJS default exports as named exports / Cannot load ES module

webpack, babel: es6 import vs. require for Fabric.js