Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

context.getPhysicalFilename is not a function #434

Closed
quisido opened this issue Sep 4, 2021 · 16 comments
Closed

context.getPhysicalFilename is not a function #434

quisido opened this issue Sep 4, 2021 · 16 comments

Comments

@quisido
Copy link

quisido commented Sep 4, 2021

eslint-plugin-prettier@4.0.0 is not compatible with eslint@7.11.0 and requires an upgrade to eslint@7.32.0. This is particularly relevant as react-scripts relies on eslint@7.11.0.

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)

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).

@romantech
Copy link

romantech commented Sep 4, 2021

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

@user12043
Copy link

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

@johannesnagl
Copy link

super helpful!

@BPScott
Copy link
Member

BPScott commented Sep 5, 2021

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 eslint@7.11.0.

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 BPScott closed this as completed Sep 5, 2021
@quisido
Copy link
Author

quisido commented Sep 5, 2021

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. 👍

@dalmo3
Copy link

dalmo3 commented Sep 9, 2021

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",

@ChristianIvicevic
Copy link

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

@netcoding87
Copy link

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 🙁

@Tesserex
Copy link

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.

@mikehardy
Copy link

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

@hongbo-miao
Copy link

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

abeforgit added a commit to lblod/ember-rdfa-editor that referenced this issue Dec 7, 2021
mrloop added a commit to mrloop/ember-sortable that referenced this issue Mar 14, 2022
mrloop added a commit to mrloop/ember-sortable that referenced this issue Mar 14, 2022
TriStarGod added a commit to TakitoTech/schemez that referenced this issue Jul 21, 2022
Replaced buggy tsdx lint jaredpalmer/tsdx#1056
Package.json eslint non standard prop fails with tsdx due to old eslint
prettier/eslint-plugin-prettier#434
@jbowen28
Copy link

jbowen28 commented Dec 8, 2022

Updated react-scripts to react-scripts@4.0.3 to resolve the incompatibility of eslint and eslint-plugin-prettier.

@hongbo-miao
Copy link

hongbo-miao commented Dec 8, 2022

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:

@cherealnice
Copy link

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

@justintemps
Copy link

I'm having this issue with eslint@8.41.0 and eslint-plugin-prettier@4.2.1 and I only have one version of eslint installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests