Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected token with import with type assertion #727

Open
remisture opened this issue Aug 6, 2023 · 3 comments
Open

Unexpected token with import with type assertion #727

remisture opened this issue Aug 6, 2023 · 3 comments

Comments

@remisture
Copy link

Seems like xo struggle to parse this. What can I do?

const serviceAccount = await import('../serviceAccount.json', { assert: { type: 'json' } });

"Parsing error: Unexpected token , "

@fregante
Copy link
Member

Not an XO issue:

Import attributes are not yet finalized so ESLint does not support them yet.

@fregante fregante closed this as not planned Won't fix, can't repro, duplicate, stale Aug 12, 2023
@fregante
Copy link
Member

It turns out this is supported by TypeScript, and XO does ship with tsc and TS ESlint plugins. So what you can do is just setting this in your package.json so that XO/ESLint will use TypeScript's parser even on JS files:

	"xo": {
		"parser": "@typescript-eslint/parser"
	},

Seen in https://github.com/refined-github/shorten-repo-url/pull/48/files#diff-e727e4bdf3657fd1d798edcd6b099d6e092f8573cba266154583a746bba0f346

Should this be documented? Or maybe become XO's default? The problem might be performance though. cc @sindresorhus

@fregante fregante reopened this Jun 23, 2024
@sindresorhus
Copy link
Member

Not sure we could do it by default (for both JS and TS files) as it could have slightly different semantics than JS. I think the best would be to simply pass the TS parser into the config when the TS config uses flat config.

@fregante fregante changed the title Unexpected token with dynamic import with type assertion Unexpected token with import with type assertion Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants