导入属性


¥Import attributes

稳定性: 2 - 稳定的

¥Stability: 2 - Stable

导入属性 是模块导入语句的内联语法,用于与模块说明符一起传递更多信息。

¥Import attributes are an inline syntax for module import statements to pass on more information alongside the module specifier.

import fooData from './foo.json' with { type: 'json' };

const { default: barData } =
  await import('./bar.json', { with: { type: 'json' } }); 

Node.js 仅支持 type 属性,它支持以下值:

¥Node.js only supports the type attribute, for which it supports the following values:

属性 type需要用于
'json'JSON 模块

导入 JSON 模块时,type: 'json' 属性是必需的。

¥The type: 'json' attribute is mandatory when importing JSON modules.