Linting 错误 `import` 只能在 `import()` 或 `import.meta` 中使用。(1:1)

for*_*ern 6 lint reactjs visual-studio-code prettier prettier-eslint

这个项目是别人写的,我需要从这里开始处理。我认为第一步应该是修复格式。通常,我只是在 vscode 中使用 .prettierrc,然后运行 ​​alt-shift-f 或 ctrl-s 来格式化每个文件中的代码。我尝试使用 eslint,但遇到了各种错误,所以我摆脱了它(卸载了项目中的所有 eslint 开发依赖项,就像我开始处理它之前的情况一样)。我在 vscode 中安装了 prettier 和 eslint 扩展。

错误

["ERROR" - 1:45:44 pm] Error formatting document.
["ERROR" - 1:45:44 pm] `import` can only be used in `import()` or `import.meta`. (1:1)
> 1 | import { subMonths, isSameDay, format, isYesterday, isToday, subDays, subYears } from 'date-fns';
    | ^
  2 |
  3 | export const today = new Date();
  4 | export const last7Day = {
SyntaxError: `import` can only be used in `import()` or `import.meta`. (1:1)
Run Code Online (Sandbox Code Playgroud)

根目录 > .vscode > settings.json

{
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "esbenp.prettier-vscode",
    // other configs
}
Run Code Online (Sandbox Code Playgroud)

根>前端>.prettierrc

{
  "arrowParens": "always",
  "bracketSpacing": true,
  "endOfLine": "lf",
  "htmlWhitespaceSensitivity": "css",
  "insertPragma": false,
  "jsxBracketSameLine": false,
  "jsxSingleQuote": false,
  "printWidth": 80,
  "proseWrap": "preserve",
  "quoteProps": "as-needed",
  "requirePragma": false,
  "semi": true,
  "singleQuote": false,
  "tabWidth": 2,
  "trailingComma": "es5",
  "useTabs": false,
  "vueIndentScriptAndStyle": false,
  "parser": "json"
}
Run Code Online (Sandbox Code Playgroud)

如何让我的更漂亮的文件忽略此错误?它出现在所有文件上。操作系统:Windows 10

更新:这是我的 package.json 中的以下内容。我通常不会安装 prettier,但我有点不知所措。根据我的理解,这更多的是 IDE 的事情,而不是项目的事情。

  "eslintConfig": {
    "extends": ["react-app", "react-app/jest"]
  },
  "browserslist": {
    "production": [">0.2%", "not dead", "not op_mini all"],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "prettier": "^2.5.1"
  }
Run Code Online (Sandbox Code Playgroud)