导入断言


¥Import assertions

稳定性: 1 - 实验性的

¥Stability: 1 - Experimental

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

¥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 模块