导入断言


🌐 Import assertions

稳定性: 1 - 实验性

导入断言提案 为模块导入语句添加了内联语法,以便在模块说明符旁传递更多信息。

🌐 The Import Assertions proposal adds an inline syntax for module import statements to pass on more information alongside the module specifier.

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

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

Node.js 支持以下 type 值,对于这些值,断言是强制性的:

🌐 Node.js supports the following type values, for which the assertion is mandatory:

断言 type所需
'json'JSON 模块