导入断言
稳定性: 1 - 实验
导入断言提案为模块导入语句添加了内联语法,以便在模块说明符旁边传入更多信息。
import fooData from './foo.json' assert { type: 'json' };
const { default: barData } =
await import('./bar.json', { assert: { type: 'json' } });
Node.js 支持以下 type
值,其断言是强制性的:
断言 type | 用于 |
---|---|
'json' | JSON 模块 |
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 supports the following type
values, for which the assertion is
mandatory:
Assertion type | Needed for |
---|---|
'json' | JSON modules |