Skip to main content

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

caution

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+ and Node.js 17.2+.

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"],
});