eslint-plugin-prettier icon indicating copy to clipboard operation
eslint-plugin-prettier copied to clipboard

context.getPhysicalFilename is not a function

Open quisido opened this issue 5 years ago • 17 comments

[email protected] is not compatible with [email protected] and requires an upgrade to [email protected]. This is particularly relevant as react-scripts relies on [email protected].

What version of eslint are you using? 7.11.0, 7.32.0

What version of prettier are you using? 2.3.2

What version of eslint-plugin-prettier are you using? 4.0.0

Please paste any applicable config files that you're using (e.g. .prettierrc or .eslintrc files)

  • https://github.com/CharlesStover/charlesstover.com/blob/1fef52f3616173c81d8b6e95f55cb817bd055ca1/.eslintrc.json
  • https://github.com/CharlesStover/charlesstover.com/blob/1fef52f3616173c81d8b6e95f55cb817bd055ca1/.prettierrc.json

What source code are you linting?

https://github.com/CharlesStover/charlesstover.com/

What did you expect to happen?

Success.

What actually happened?

https://github.com/CharlesStover/charlesstover.com/runs/3511215999?check_suite_focus=true

Run yarn build
Creating an optimized production build...
Failed to compile.

Error while loading rule 'prettier/prettier': context.getPhysicalFilename is not a function
Occurred while linting /home/runner/work/charlesstover.com/charlesstover.com/src/index.tsx

Error: Process completed with exit code 1.

However, you can see from the eslint step that running eslint succeeds. The only two differences between these two steps is the version of ESLint being run.

By upgrading react-scripts's eslint version with yarn up -R eslint, this error is resolved.

I'm opening this issue for two reasons:

  1. Anyone also encountering this error has an easily-googleable solution that does not otherwise exist at time of posting. To re-iterate, that solution is yarn up -R eslint.
  2. The documentation should probably mention this, just based on the popularity of react-scripts. 🙂

I noticed this package lists the correct semvar in peer dependencies, but there are no warning or errors about versioning in the logs (see: GitHub workflow links above).

quisido avatar Sep 04 '21 02:09 quisido

I had same problem. After deeleting node_modules, package-lock.json and reinstall dependency, then works fine.

romantech avatar Sep 04 '21 10:09 romantech

Same problem here. Solved by yarn upgrade -R eslint as you mentioned. Thank you!

user12043 avatar Sep 04 '21 18:09 user12043

super helpful!

johannesnagl avatar Sep 04 '21 19:09 johannesnagl

As first line of the CHANGELOG entry for v4.0.0 states:

This breaking change drops support for old versions of ESLint, Prettier and Node. You must use at least ESLint v7.28.0, Prettier v2.0.0 and Node v12.0.0. Aside from that, usage of this plugin remains identical.

Because the peer-dependency is also set as to v7.28.0 you probably got n warning when you ran your yarn / npm install that stated that the eslint version you have installed does not match what was required by peer dependencies.


This is particularly relevant as react-scripts relies on [email protected].

react-scripts relies on eslint@^7.11.0 according to your own yarn.lock. That means any fresh installs of react-scripts will pick up newer versions of eslint, so this isn't an issue for new users. It only affects people that have an existing install of an older eslint version, and telling people how to their dependency manager isn't the scope of this project.

BPScott avatar Sep 05 '21 19:09 BPScott

As first line of the CHANGELOG entry for v4.0.0 states:

Users who have ESLint >=7.28 installed can still encounter this error when using other dependencies that depend on ESLint. My suggestion was for the documentation to address how to resolve this error, which the CHANGELOG neither does nor is it easily accessible, versus the README or an FAQ.

Because the peer-dependency is also set as to v7.28.0 you probably got n warning when you ran your yarn / npm install that stated that the eslint version you have installed does not match what was required by peer dependencies.

There in fact is not a warning, because I have both versions of ESLint installed. That is the point of this issue. It is quite possible for users to have both installed and get no warnings. They only get cryptic errors which do not tell how to resolve the issue.

react-scripts relies on eslint@^7.11.0 according to your own yarn.lock. That means any fresh installs of react-scripts will pick up newer versions of eslint, so this isn't an issue for new users.

Correct.

It only affects people that have an existing install of an older eslint version, and telling people how to their dependency manager isn't the scope of this project.

I feel like unblocking users who encounter common errors is within scope. "I installed react-scripts before late 2021" probably represents >90% of React users. I'm not saying it's this project's responsibility to fix the error. I'm saying it's this project's responsibility to help users onboard. The root cause and solution were outlined in the OP. It's minimal effort to point to it as a debug step.

Nonetheless, my intention was for it to become Google-able, as there were zero results for this error previously. Hopefully that goal is still met, even if the project doesn't formally support the unblocking process. 👍

quisido avatar Sep 05 '21 19:09 quisido

Also "solved" by reverting to 3.3.1 I guess? This has been working for me:

    "eslint": "^7.32.0",
    "react-scripts": "^4.0.3", 
    "eslint-plugin-prettier": "3.3.1",

dalmo3 avatar Sep 09 '21 08:09 dalmo3

Small addition: if you're using yarn v2+ the command has been renamed to the following yarn up -R eslint.

ChristianIvicevic avatar Sep 09 '21 13:09 ChristianIvicevic

Another addition:

react-scripts relies on eslint@^7.11.0 according to your own yarn.lock. That means any fresh installs of react-scripts will pick up newer versions of eslint, so this isn't an issue for new users.

Unfortunately this seems not to be correct. Creating a new react app using cra installs current react-scripts 4.0.3 but eslint in version 7.20.0 🙁

netcoding87 avatar Sep 10 '21 07:09 netcoding87

For what it's worth, googling this error brought me straight here, and the advice to upgrade to 7.32.0 worked for me. So I guess just filing this issue is a good start to help new people.

Tesserex avatar Sep 11 '21 13:09 Tesserex

I had something else triggering this where just doing a recursive update wasn't persistent for me - deleting yarn.lock and reinstalling, or doing recursive upgrade didn't work, I didn't inspect too much because it also works if you just put a resolutions block in your package.json:

resolutions: {
  eslint: "^version-that-works-here"
}

mikehardy avatar Sep 16 '21 16:09 mikehardy

Hmm, anyone know what is the equal command of yarn up -R eslint for npm? Thanks!

hongbo-miao avatar Oct 01 '21 19:10 hongbo-miao

https://stackoverflow.com/questions/69069719/error-while-loading-rule-prettier-prettier-context-getphysicalfilename-is-not

yarn upgrade -R eslint

April-Zheng avatar Dec 07 '21 06:12 April-Zheng

Updated react-scripts to [email protected] to resolve the incompatibility of eslint and eslint-plugin-prettier.

jbowen28 avatar Dec 08 '22 15:12 jbowen28

Hmm, anyone know what is the equal command of yarn up -R eslint for npm? Thanks!

Just add a follow up to my original question:

  • This upgrading eslint-plugin-prettier from 3.4.1 to 4 pull request from Renovate which fails all the time since 8/30/2021: https://github.com/Hongbo-Miao/hongbomiao.com/pull/3270
  • Since then Renovate keeps trying all the time and finally succeed on 1/11/2022: https://github.com/Hongbo-Miao/hongbomiao.com/pull/4185 .
    • I didn't do anything on purpose to fix this, so I guess some sub dependencies get upgraded during this period and make this issue disappeared.
    • In my case, it is not related with react-scripts as it got upgraded to 4.0.3 on 2/22/2021 which is one year earlier before eslint-plugin-prettier succeed upgrading from 3.4.1 to 4 on 1/11/2022

hongbo-miao avatar Dec 08 '22 17:12 hongbo-miao

I got this recently due to multiple eslint versions being installed in my monorepo. Resolved the issue and it's better now :)

cherealnice avatar May 05 '23 08:05 cherealnice

I'm having this issue with [email protected] and [email protected] and I only have one version of eslint installed.

justintemps avatar May 25 '23 15:05 justintemps

Fixed after updating ESLint

 "eslint": "8.57.0",
 "prettier": "3.2.5",
  "eslint-plugin-prettier": "^5.1.3",

CyxouD avatar May 25 '24 11:05 CyxouD