Plugin-php: SyntaxError: Unexpected token after install

Created on 19 Feb 2018  ·  17Comments  ·  Source: prettier/plugin-php

Having installed prettier and @prettier/plugin-php globally, I cannot seem to get prettier to work on any php files, it always results in a syntax error.

Am I doing something wrong?
image

needs investigation

All 17 comments

I'm having the same issue - not using globally installed prettier though.

I _believe_ you still need to specify the plugin manually, although that does seem to contradict the prettier docs. @azz or @vjeux do you guys have any more info on how plugins are intended to be run from a cli?

@mgrip I tried that as well, without luck.

The command I attempted,

yarn prettier --plugin=./node_modules/@prettier/plugin-php app/Http/Controllers/ReserveController.php

here's some more info,

❯: cat package.json | rg "prettier"
    "prettier": "1.10.2",
    "@prettier/plugin-php": "0.0.0-development",
    "eslint-config-prettier": "^2.4.0",
    "eslint-plugin-prettier": "^2.2.0",
    "prettier-eslint": "^8.2.1",


❯: yarn --version
1.3.2

❯: yarn prettier --version
yarn run v1.3.2
$ /Users/camron/src/lodgetools/inntender/node_modules/.bin/prettier --version
1.10.2

edited to use the package.json from the correct branch

what's the error you get when manually specifying the plugin? I'm guessing the package might have to be updated on npm - there have been a lot of changes since @azz originally published it

❯: yarn prettier --plugin=./node_modules/@prettier/plugin-php app/Http/Controllers/ReserveController.php
yarn run v1.3.2
$ /Users/camron/src/lodgetools/inntender/node_modules/.bin/prettier --plugin=./node_modules/@prettier/plugin-php app/Http/Controllers/ReserveController.php

[error] app/Http/Controllers/ReserveController.php: SyntaxError: Unexpected token (1:2)
[error] > 1 | <?php
[error]     |  ^
[error]   2 | 
[error]   3 | namespace InnTender\Http\Controllers;
[error]   4 | 
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@vjeux @azz do you guys know how the plugins are intended to be run from the cli? the docs make its seem like plugins are intended to be found automatically, but it doesn't seem like thats happening

I don’t know, @azz built all the support for it.

Confirm don't work as expected

Ok think I got something that will at least work for now. 2 main things
1) you still need to specify the parser
2) while we're developing you should probably use the repos as dependencies rather than whats published on npm as things are getting updated very quickly

so this should work
yarn add --dev prettier/prettier prettier/plugin-php
prettier --parser=php /some/php/file.php

I can update the readme accordingly

/cc @azz

@camflan @pjhartin can you guys see if that worked when you have a chance? if so I'll close this out for now

Pretty sure this is working - gonna close for now

@mgrip yep, those steps worked. Not sure why reinstalling prettier as prettier/prettier works but my existing install would fail.

Thanks 👍

Sent with GitHawk

i believe its because prettier would just add whatever the latest version published to npm is, prettier/prettier references the git repo (and there are recent changes that the plugins rely on)

Oh, ok!

  • Camron

On Feb 22, 2018, at 10:32 AM, Mike Grip notifications@github.com wrote:

i believe its because prettier would just add whatever the latest version published to npm is, prettier/prettier references the git repo (and there are recent changes that the plugins rely on)


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@mgrip Thanks, I followed your instructions and all seemed to work well.i did notice however that a number of phpDoc comments within my phone code were being stripped away by prettier though. So I'm not 100% on using it right now.

@pjhartin Please raise bugs for those items!

@mgrip Sorry for the delay in responding. Fixing it in https://github.com/prettier/prettier/pull/4038.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sgruetter picture sgruetter  ·  5Comments

ichiriac picture ichiriac  ·  3Comments

alexander-akait picture alexander-akait  ·  5Comments

czosel picture czosel  ·  4Comments

virgofx picture virgofx  ·  4Comments