[英]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?哪个文件、
import
ing 文件、 .mjs
export
扩展名?
Specifically for NodeJS.专门针对 NodeJS。
I have searched the web but didn't get my exact answer.我已经搜索了 web 但没有得到我的确切答案。
Thanks in advance!提前致谢!
I think just the one that uses the import should be in .mjs
.我认为只有使用导入的那个应该在
.mjs
中。 From the docs :从文档:
An import statement can reference an ES module or a CommonJS module.
import 语句可以引用 ES 模块或 CommonJS 模块。 import statements are permitted only in ES modules, but dynamic import() expressions are supported in CommonJS for loading ES modules.
import 语句只允许在 ES 模块中使用,但 CommonJS 支持动态 import() 表达式来加载 ES 模块。
When importing CommonJS modules , the module.exports object is provided as the default export .
导入 CommonJS 模块时, module.exports object 作为默认导出提供。 Named exports may be available, provided by static analysis as a convenience for better ecosystem compatibility.
命名导出可能可用,由 static 分析提供,以方便实现更好的生态系统兼容性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.