沉冰浮水

沉冰浮水

做最终到的事,成为最终成为的人!
github
bilibili
mastodon
zhihu
douban

「Node.js」import 引入 JSON 文件的问题 - rollup && eslint

rollup 2.x 版本是可以直接这么写的:

// rollup.config.js
import pkg from "./package.json";

升级 3.15 后报错;

[!] TypeError: Module "./package.json" needs an import assertion of type "json"

修改后 eslint 又会报错:

// rollup.config.js
import pkg from "./package.json" assert { type: "json" };
// Parsing error: Unexpected token assert ← eslint

进一步解决:

cnpm i -D eslint @babel/core @babel/eslint-parser @babel/plugin-syntax-import-assertions
// .eslintrc.js
"parser": "@babel/eslint-parser",
"parserOptions": {
    "requireConfigFile": false,
    "babelOptions": {
        "plugins": [
            '@babel/plugin-syntax-import-assertions'
        ],
    },
    "ecmaVersion": "latest",
    "sourceType": "module",
},

就挺麻烦的 - -

· · · · · ·

「折腾」ESLint 安装与使用_电脑网络_沉冰浮水:

https://www.wdssmq.com/post/20190917021.html

Support of assert {type: "json"} · Discussion #15305 · eslint/eslint:

https://github.com/eslint/eslint/discussions/15305#discussioncomment-2508948

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.