Skip to main content

@babel/plugin-syntax-import-attributes

info

This plugin is included in @babel/preset-env, in ES2025

note

Syntax only

This plugin only enables Babel to parse and generate this syntax. Babel does not support transforming this syntax.

While Babel supports parsing import attributes by default since v7.25.0, this plugin is still needed to let Babel choose the correct syntax when emitting code. As an alternative to this plugin, you can use @babel/generator's importAttributesKeyword option:

{
"generatorOpts": {
"importAttributesKeyword": "with"
},
}

:::

This plugin enables Babel to parse import attributes:

JavaScript
import foo from "./foo.json" with { type: "json" };

Installation

npm install --save-dev @babel/plugin-syntax-import-attributes

Usage

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

Via CLI

Shell
babel --plugins @babel/plugin-syntax-import-attributes script.js

Via Node API

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

Options

deprecatedAssertSyntax

boolean, defaults to false.

If enabled, support parsing import attributes using the deprecated assert keyword:

JavaScript
import foo from "./foo.json" assert { type: "json" };

This syntax is only supported in V8-based engines, and its removal from the web is being investigated.