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