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

SyntaxError: ';' expected in package.json #23

Closed
BuZZ-dEE opened this issue Mar 1, 2018 · 9 comments
Closed

SyntaxError: ';' expected in package.json #23

BuZZ-dEE opened this issue Mar 1, 2018 · 9 comments
Assignees
Labels
out of scope This will not be worked on

Comments

@BuZZ-dEE
Copy link

BuZZ-dEE commented Mar 1, 2018

I'm trying to commit the following:

⋊> ~/W/web-app on prettier ⨯   git diff --staged                                                                                                                              14:20:30
diff --git a/package.json b/package.json
index b7801607..703581e1 100644
--- a/package.json
+++ b/package.json
@@ -15,7 +15,7 @@
     "buildwatcher": "ng build --watch",
     "pree2e": "webdriver-manager update",
     "e2e": "ng e2e",
-    "precommit": "pretty-quick --staged"
+    "precommit": "pretty-quick --staged",
     "tslint-check": "tslint-config-prettier-check ./tslint.json"
   },
   "private": true,

but I get the following error:

⋊> ~/W/web-app on prettier ⨯   git commit -m "Add missing comma"                                                                                                              14:16:32
husky > npm run -s precommit (node v6.10.2)

🔍  Finding changed files since git revision 9cb1833d.
🎯  Found 1 changed file.
/home/user/Workspace/web-app/node_modules/prettier/index.js:24285
      throw error;
      ^

SyntaxError: ';' expected. (2:9)
  1 | {
> 2 |   "name": "web-app",
    |         ^
  3 |   "version": "0.0.0",
  4 |   "license": "MIT",
  5 |   "angular-cli": {},
    at createError (/home/user/Workspace/web-app/node_modules/prettier/parser-typescript.js:1:194)
    at Object.parse (/home/user/Workspace/web-app/node_modules/prettier/parser-typescript.js:1:18102)
    at Object.parse$4 [as parse] (/home/user/Workspace/web-app/node_modules/prettier/index.js:24274:19)
    at formatWithCursor (/home/user/Workspace/web-app/node_modules/prettier/index.js:33650:27)
    at format (/home/user/Workspace/web-app/node_modules/prettier/index.js:33695:10)
    at format (/home/user/Workspace/web-app/node_modules/prettier/index.js:33945:12)
    at exports.default (/home/user/Workspace/web-app/node_modules/pretty-quick/dist/formatFiles.js:18:41)
    at exports.default (/home/user/Workspace/web-app/node_modules/pretty-quick/dist/index.js:48:29)
    at Object.<anonymous> (/home/user/Workspace/web-app/node_modules/pretty-quick/bin/pretty-quick.js:12:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:393:7)

husky > pre-commit hook failed (add --no-verify to bypass)
@azz
Copy link
Member

azz commented Mar 3, 2018

Looks like it thinks it is TypeScript for some reason? Which version of Prettier are you using?

@erincarignan
Copy link

I'm running into this same issue - trying to follow the instructions here: https://medium.com/@victormejia/setting-up-prettier-in-an-angular-cli-project-2f50c3b9a537.
I have version 1.11.1 of Prettier, and 1.4.1 of pretty-quick.

@akodkod
Copy link

akodkod commented Mar 19, 2018

Yeah, guys. I got the same error.

@azz
Copy link
Member

azz commented Mar 19, 2018

If anyone can put together a concrete set of reproduction steps, or repository, that would go a long way towards getting this fixed.

@BuZZ-dEE
Copy link
Author

I'm using:
"prettier": "1.10.2",

@BuZZ-dEE
Copy link
Author

BuZZ-dEE commented Mar 26, 2018

I now created a new Typescript project and I had the same problem (that I can not commit changes in the package.json). I also saw that in the .prettierignore file from the prettier-vscode repository the package.json is ignored.

To reproduce the error, you can clone my Typescript project, remove package.json from the .prettierignore file. Then change in the package.json scripts.test to "mocha -r ts-node/register 'src/**/*.spec.ts'" and try to commit that.

@azz azz added the bug Something isn't working label Mar 28, 2018
@azz azz self-assigned this Mar 28, 2018
@azz
Copy link
Member

azz commented May 9, 2018

(Sorry for the long delay)

@BuZZ-dEE Found the issue with your setup, I suspect this is what is happening to everyone.

Your .prettierrc file has parser: typescript. This is picked up by pretty-quick and overrides the extension-based parser inference. Fix is to remove the parser setting and let Prettier figure it out from the extension.

@azz azz closed this as completed May 9, 2018
@azz azz added out of scope This will not be worked on and removed bug Something isn't working labels May 9, 2018
@BuZZ-dEE
Copy link
Author

BuZZ-dEE commented May 9, 2018

Yes ok, but why is it not also corrected in pretty-quick?

@azz
Copy link
Member

azz commented May 9, 2018

Because it's not a bug. The config file is effectively saying "For all files, use the typescript parser". There's nothing that can really be done in pretty-quick.

zhaoyao91 added a commit to zhaoyao91/create-snowpack-app that referenced this issue Jun 19, 2020
with parser set to typescript, it cannot format json files.
see prettier/pretty-quick#23 (comment)
FredKSchott pushed a commit to FredKSchott/create-snowpack-app that referenced this issue Jun 19, 2020
with parser set to typescript, it cannot format json files.
see prettier/pretty-quick#23 (comment)
drwpow pushed a commit to FredKSchott/snowpack that referenced this issue Jul 24, 2020
with parser set to typescript, it cannot format json files.
see prettier/pretty-quick#23 (comment)
drwpow pushed a commit to FredKSchott/snowpack that referenced this issue Jul 27, 2020
with parser set to typescript, it cannot format json files.
see prettier/pretty-quick#23 (comment)
drwpow pushed a commit to FredKSchott/snowpack that referenced this issue Jul 27, 2020
with parser set to typescript, it cannot format json files.
see prettier/pretty-quick#23 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
out of scope This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants