--experimental-default-type=type
为以下内容定义使用哪种模块系统,module 或 commonjs:
🌐 Define which module system, module or commonjs, to use for the following:
- 如果未指定
--input-type,则通过--eval或 STDIN 提供字符串输入。 - 以
.js结尾的文件或没有扩展名的文件,如果在同一文件夹或任何父文件夹中没有package.json文件存在。 - 以
.js结尾的文件或没有扩展名的文件,如果最近的父级package.json文件缺少"type"字段;除非package.json所在文件夹或任何父级文件夹位于node_modules文件夹内。
换句话说,--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.