简体   繁体   中英

Which should have .mjs extension, the importing file or the exporting file, or both?

I have a silly doubt. Which file, the import ing file, the export ing file or both should have the .mjs file extension?

Specifically for NodeJS.

I have searched the web but didn't get my exact answer.

Thanks in advance!

I think just the one that uses the import should be in .mjs . From the docs :

An import statement can reference an ES module or a CommonJS module. import statements are permitted only in ES modules, but dynamic import() expressions are supported in CommonJS for loading ES modules.

When importing CommonJS modules , the module.exports object is provided as the default export . Named exports may be available, provided by static analysis as a convenience for better ecosystem compatibility.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM