导入属性


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