跳到主要内容

@babel/plugin-proposal-import-attributes-to-assertions

警告

This plugin will generate code that is not compatible with the current ECMAScript specification or with any currently proposed addition to it. Only use it when you are shipping native ES modules and you need compatibility exclusively with tools that don't support the Import Attributes syntax (import pkg from "./package.json" with { type: "json" }) but support the old Import Assertions syntax (import pkg from "./package.json" assert { type: "json" }), such as Chrome 91 - 122 and Node.js ^16.14 || ^18 || ^20 < 20.10.

Installation

npm install --save-dev @babel/plugin-proposal-import-attributes-to-assertions

Usage

babel.config.json
{
"plugins": ["@babel/plugin-proposal-import-attributes-to-assertions"]
}

Via CLI

Shell
babel --plugins @babel/plugin-proposal-import-attributes-to-assertions script.js

Via Node API

JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-proposal-import-attributes-to-assertions"],
});