导入属性


【Import attributes】

导入属性 是一种内联语法,用于模块导入语句,以便在模块指定符旁传递更多信息。

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.】