DEV Community

loading...

Discussion on: ES6 Import And Export Cheatsheet

Collapse
akman profile image
Giannis Akmanidis

Nice Post!
but i wonder if the statment :
"Note that while importing something from the file, we don't need to add the .js extension to the filename as it's considered by default." is completely true.

All the time i use imports without ext the browsers complain, so i have to use a file extension. Which usually is .mjs so it is easier to distinguish modules.

Collapse
myogeshchavan97 profile image
Yogesh Chavan Author

@akman If you're using any module bundler like webpack which React.js uses then you don't need to include the .js extension as it's optional. If want to use Es6 Import-export syntax inside Node.js then you may need to add .mjs extension as by default Node.js supports commonJS syntax and not ES Module syntax.

Collapse
akman profile image
Giannis Akmanidis

probably… but i use native JavaScript modules and not bundlers so i have to use extensions

Thread Thread
myogeshchavan97 profile image
Yogesh Chavan Author

Okay