最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there a way to make ESLint understand the new import assertion syntax without adding Babel? - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question edited Feb 12, 2022 at 10:23 jonrsharpe 122k30 gold badges266 silver badges473 bronze badges asked Feb 12, 2022 at 10:17 dennisdennis 8651 gold badge12 silver badges30 bronze badges 1
  • That's only a stage 3 proposal so will not yet be included natively in ESLint: github.com/eslint/eslint/discussions/15305 – jonrsharpe Commented Feb 12, 2022 at 10:20
Add a comment  | 

2 Answers 2

Reset to default 11

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"
      ]
    }
  },

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论