简体   繁体   English

哪个应该有.mjs 扩展名,导入文件或导出文件,或两者兼而有之?

[英]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.

相关问题 using.mjs 文件扩展名 js 模块 - using .mjs file extension js modules 目标“main”中的意外输出文件类型为 .html(^^^^^^^^^^^^ 文件扩展名必须为 .js、.mjs 或 .cjs) - Unexpected output file type .html in target "main" (^^^^^^^^^^^^ File extension must be .js, .mjs, or .cjs) JavaScript ES6 模块基本问题:.mjs 文件扩展名和 MIME 类型 - JavaScript ES6 Module basic question: .mjs file extension and MIME type 为什么 Javascript 模块在导入时找不到带有“.js”文件扩展名的模块,除非文件扩展名是 .mjs,尽管 package“类型”是“模块”? - Why is Javascript module with ".js" file extension not found on import unless file extension is .mjs despite package "type" being "module"? ES6 在索引文件中导出/导入 - ES6 exporting/importing in index file 导入文件前检查文件扩展名 - Check file extension before importing file 切换到mjs文件后用import替换require - Replace require with import after switching to mjs file Nodejs - 将 mjs 文件中的内容导入 js 文件或如何在 mjs 文件中使用 require? - Nodejs - import stuff from mjs file into js file OR how to use require in mjs file? 将仅具有特定文件扩展名的图像导入Photoshop - Importing images with only specific file extension into Photoshop 加载 ecmascript 模块(.mjs 文件)作为 nodejs cli 的主要入口 - load ecmascript module (.mjs file) as main entry of nodejs cli
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM