加载规则“更漂亮/更漂亮”时出错:context.getPhysicalFilename 不是函数

贾瓦德·本·莫宾·阿基布

我正在学习 React js。我是这个主题的初学者。但是当我进行设置以创建反应环境时,出现错误。我试图通过Charles Stover 博客在 medium 中解决这个问题但我有一个错误Command "up" not found

这是我的 index.js 文件:

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import reportWebVitals from './reportWebVitals';
ReactDOM.render(
   <React.StrictMode>
      <App />
   </React.StrictMode>,
document.getElementById('root')
);
reportWebVitals();

我的 package.json 文件:

{
  "name": "myreact",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "4.0.3",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "lint": "yarn add -D prettier && yarn add -D babel-eslint && npx install-peerdeps --dev eslint-config-airbnb && yarn add -D eslint-config-prettier eslint-plugin-prettier"
  },
  "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": {
    "babel-eslint": "^10.1.0",
    "eslint": "7.2.0",
    "eslint-config-airbnb": "18.2.1",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-import": "2.22.1",
    "eslint-plugin-jsx-a11y": "6.4.1",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-react": "7.21.5",
    "eslint-plugin-react-hooks": "1.7.0",
    "prettier": "^2.3.2"
  }
}

当我yarn start在终端中运行时,出现错误。

Error while loading rule 'prettier/prettier': context.getPhysicalFilename is not a function
Occurred while linting F:\react-projects\myreact\src\index.js

现在我该怎么办?

贾瓦德·本·莫宾·阿基布

我得到了两种不同的解决方案。

  1. 消除
"prettier/prettier": [
            "error",
            {
                "trailingComma": "es5",
                "singleQuote": true,
                "printWidth": 100,
                "tabWidth": 4,
                "semi": true,
                "endOfLine": "auto"
            }
        ]

.eslintrc文件夹并将反应脚本版本从 4.0.3 更改为 4.0.1 并运行npm install.

  1. 使用yarn upgrade -R eslint并将 react 脚本版本从 4.0.3 更改为 4.0.1 并运行npm install.

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章