Skip to content

Babel plugin importAttributes can't be enabled and formatting fails #15911

@hdodov

Description

@hdodov

I'm trying to format a TypeScript file called index.ts with the following line inside:

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

…but I get the following error:

[error] src/index.ts: SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): "importAttributes", "importAssertions". (3:37)

I tried adding a babel.config.json file containing the following:

{
	"plugins": ["importAttributes"],
	"parserOpts": {
		"plugins": ["importAttributes"]
	}
}

…but it didn't work.

I also tried installing @babel/plugin-syntax-import-assertions and putting it in babel.config.json, .babelrc, .prettierrc.json as well, etc, but nothing seems to enable the plugin.

Environments:

  • Prettier Version: 3.1.1, @babel/parser 7.23.6 (from package-lock.json)
  • Running Prettier via: npx prettier --write .
  • Runtime: Node v20.9.0, npm 10.1.0
  • Operating System: macOS Ventura 13.6.3
  • Prettier plugins (if any): @trivago/prettier-plugin-sort-imports (don't think it's relevant)

Steps to reproduce:

Try to format the aforementioned line with Prettier 3.1.1 and you'll see an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions