Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while loading rule 'prettier/prettier': context.getPhysicalFilename is not a function

Tags:

reactjs

I am learning react js. I am a very beginner at this topic. But when I am doing setup to create a react environment I got an error. I have tried to solve the problem by Charles Stover blog in medium. But I got an error Command "up" not found.

Here's my index.js file:

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();

My package.json file:

{
  "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"
  }
}

When I am running yarn start in terminal, I am getting an error.

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

Now what should I do?

like image 858
Jawad Bin Mobin Akib Avatar asked Sep 06 '21 05:09

Jawad Bin Mobin Akib


People also ask

How can I disable the error prettier prettier on ESLint?

eslint disable Delete 'cr' [prettier/prettier]? remove eslint-disable-next-line to ignore the next line. eslint-disable-next-line to ignore the next line.

How do I enable prettier in react?

Open the terminal in your project root folder and install eslint as a dev dependency. We also need to enable the eslint and prettier extension for the VSCode. So visit the extensions section of VSCode (ctrl + shift + x) and search for Eslint and Prettier — Code formatter and install it.

Can I use ESLint with prettier?

You can use ESLint plugins that let you run Prettier as if it is a linter rule: eslint-plugin-prettier for JavaScript.


Video Answer


1 Answers

I got two different solution.

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

from .eslintrc folder and change react script version from 4.0.3 to 4.0.1 and run npm install.

  1. Use yarn upgrade -R eslint and change react script version from 4.0.3 to 4.0.1 and run npm install.
like image 194
Jawad Bin Mobin Akib Avatar answered Sep 22 '22 09:09

Jawad Bin Mobin Akib