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

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

升级 3.15 后报错;

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

修改后 eslint 又会报错:

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

进一步解决:

1
cnpm i -D eslint @babel/core @babel/eslint-parser @babel/plugin-syntax-import-assertions
1
2
3
4
5
6
7
8
9
10
11
12
// .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