@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
- Yarn
- pnpm
npm install --save-dev @babel/plugin-proposal-import-attributes-to-assertions
yarn add --dev @babel/plugin-proposal-import-attributes-to-assertions
pnpm add --save-dev @babel/plugin-proposal-import-attributes-to-assertions
Usage
With a configuration file (Recommended)
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"],
});