--experimental-default-type=type
¥Stability: 1.0 - Early development
定义用于以下目的的模块系统 module
或 commonjs
:
¥Define which module system, module
or commonjs
, to use for the following:
-
如果未指定
--input-type
,则通过--eval
或 STDIN 提供字符串输入。¥String input provided via
--eval
or STDIN, if--input-type
is unspecified. -
如果同一文件夹或任何父文件夹中不存在
package.json
文件,则以.js
结尾或没有扩展名的文件。¥Files ending in
.js
or with no extension, if there is nopackage.json
file present in the same folder or any parent folder. -
如果最近的父
package.json
字段缺少"type"
字段,则以.js
结尾或没有扩展名的文件;除非package.json
文件夹或任何父文件夹位于node_modules
文件夹内。¥Files ending in
.js
or with no extension, if the nearest parentpackage.json
field lacks a"type"
field; unless thepackage.json
folder or any parent folder is inside anode_modules
folder.
换句话说,--experimental-default-type=module
将 Node.js 当前默认为 CommonJS 的所有位置翻转为默认为 ECMAScript 模块(node_modules
以下的文件夹和子文件夹除外),以实现向后兼容性。
¥In other words, --experimental-default-type=module
flips all the places where
Node.js currently defaults to CommonJS to instead default to ECMAScript modules,
with the exception of folders and subfolders below node_modules
, for backward
compatibility.
在 --experimental-default-type=module
和 --experimental-wasm-modules
下,没有扩展名的文件如果以 WebAssembly 幻数 (\0asm
) 开头,将被视为 WebAssembly;否则它们将被视为 ES 模块 JavaScript。
¥Under --experimental-default-type=module
and --experimental-wasm-modules
,
files with no extension will be treated as WebAssembly if they begin with the
WebAssembly magic number (\0asm
); otherwise they will be treated as ES module
JavaScript.