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

can't format php code #234

Open
heheda123123 opened this issue Jul 19, 2023 · 6 comments
Open

can't format php code #234

heheda123123 opened this issue Jul 19, 2023 · 6 comments

Comments

@heheda123123
Copy link

when use format-all-buffer for any php file, it shows

[error] Couldn't resolve parser "php".

in *format-all-errors*
image
I already install the plugin
image

@lassik
Copy link
Owner

lassik commented Jul 19, 2023

Are your PHP files in a Node project (with its own package.json)? In that case, it might work to try npm install prettier @prettier/plugin-php with no --global option.

@heheda123123
Copy link
Author

no, it's just a single php file

@lassik lassik added the help wanted Extra attention is needed label Jul 19, 2023
@heheda123123
Copy link
Author

in a different computer, create a simple php file, still have this problem
image

@claytonrcarter
Copy link

Just ran into the same issue, also on a one-off project w/ no package.json, but it's nothing to do w/ this package. It's related to a breaking change in prettier v3. More info here: prettier/plugin-php#2215

I have worked around it by putting a .prettierrc.json in $HOME and explicitly adding plugins that way:

{
    "plugins": [
        "/usr/local/lib/node_modules/@prettier/plugin-php/src/index.js"
    ]
}

With this, prettier on the CLI and via emacs starts working again. (prettier searchs for configs up from the file being formatted, and – in my case – all of my code is in $HOME/src. If you put your code elsewhere, you should adjust accordingly.)

(BTW Apparently global installs still can't handle short plugin names like @prettier/plugin-php, so the full path is required.)

@lassik
Copy link
Owner

lassik commented Sep 12, 2023

Thanks, glad to have this sorted out. This is excellent information. We should add this link to the readme if more people stumble upon the same problem.

@lassik lassik removed the help wanted Extra attention is needed label Sep 12, 2023
@rdbeni0
Copy link

rdbeni0 commented Jun 22, 2024

little update - this is upstream issue:

prettier/prettier#15141

https://github.com/auvred/prettier-pnp

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

4 participants