Reputation: 865
Since the import assertion syntax (e.g. assert {type: 'json'}
) is mandatory in the latest Node.js versions, I'm looking for a way to be able to write this new syntax, but I don't want to add Babel just to be able to use the Babel ESLint parser which understands it.
Could this be added by a different ESLint plugin?
Upvotes: 15
Views: 5313
Reputation: 70075
As of this writing, the Node.js core code itself is configured to use @babel/eslint-parser
specifically for this. It is unlikely that there is an easy and reliable way to do it using a parser shipped with ESLint (at this time). As of February 2023, the specification is Stage 2. ESLint has a policy of only adding Stage 4 syntax. Additionally, Node.js docs and a runtime warning make it clear that this is an experimental API. Installing @babel/eslint-parser
is the reasonable solution if you're using an experimental API.
Upvotes: 10
Reputation: 1579
You have to use the babel eslint parser for that
npm i -D @babel/eslint-parser @babel/plugin-syntax-import-assertions
then in .eslintrc
"parser": "@babel/eslint-parser",
"parserOptions": {
"requireConfigFile": false,
"babelOptions": {
"plugins": [
"@babel/plugin-syntax-import-assertions"
]
}
},
Upvotes: 11