prettier / prettier-vscode

Visual Studio Code extension for Prettier
https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
MIT License
5.04k stars 446 forks source link

eslintIntegration. Cannot read property 'sync' of undefined #235

Closed dcorb closed 6 years ago

dcorb commented 6 years ago

It's the first time I'm trying to set it up, so I might have skipped something obvious, but can't figure it out.

After CMD + Shift + P -> Format Document , it shows in the Output tab:

Cannot read property 'sync' of undefined image

I just installed the extension today, version 0.24 Settings of the plugin: { "prettier.eslintIntegration": true }

prettier 1.6.1 eslint 4.8.0 . (installed globally)

.eslintrc content is:

{
    "extends": [
        "plugin:react/recommended"
    ],
    "plugins": [ "react" ],
    "parserOptions": {
        "ecmaVersion": 8,
        "sourceType": "module",
        "ecmaFeatures": {
            "impliedStrict": true,
            "jsx": true
        }
    }
}
dcorb commented 6 years ago

in package.json of the project we have "prettier-eslint": "^6.4.1", (although prettier is installed globally)

I also enabled VS Code DevTools, nothing there

azz commented 6 years ago

Prettier 1.7.0 has the sync() function that is missing here (1.6.1)

https://github.com/prettier/prettier/commit/088aa71b07bc25bc3640b1e188ec906ef6d17b1b

CiGit commented 6 years ago

What I read here is not missing sync function but missing member. Could you find a stack trace?

azz commented 6 years ago

https://github.com/prettier/prettier-eslint/releases/tag/v6.4.3

prettier-eslint bundles in prettier and 1.6.0 of prettier was added in 6.4.3. Upgrading prettier-eslint should fix the problem.

CiGit commented 6 years ago

Sorry, forgot to mention. We don't use user's installed version. https://github.com/prettier/prettier-vscode/blob/master/src/PrettierEditProvider.ts#L125

We bundle prettier-eslint@8.2

azz commented 6 years ago

Ah, didn't know that. What are the possible ways it is resolving prettier <1.6?

CiGit commented 6 years ago

It's the one installed locally. This is the case, but we use resolveConfig (async version) from our bundled prettier

In

Cannot read property 'sync' of undefined

It's not sync which makes me think of a problem, but undefined

The only .sync in our src is here: https://github.com/prettier/prettier-vscode/blob/master/src/requirePkg.ts#L14 This line shouldn't be hit with eslint.

dcorb commented 6 years ago

Thanks for the help, I updated prettier globally to latest, didn't work Then, update prettier-eslint, I got 6.4.3 version .. and after restarting VSCode it worked ! Thanks for the fast replies guys, appreciated!

CiGit commented 6 years ago

So the fix is "restart vscode" ?

Out of curiosity, have you restarted vscode in those last 2 days? (since you installed last release )

nealoke commented 6 years ago

@CiGit the fix in my case was removing prettier from my node_modules, adjusting my package.json file to use the latest version of prettier (1.7.4) and hitting npm install. Ofcourse restart vscode after 👍

CiGit commented 6 years ago

So prettier@1.6.1 + eslintIntegration fails?

CiGit commented 6 years ago

Just tried and it works on my machine :-)

What doesn't is with prettier 1.5 ...

prettier.resolveConfig is not a function

in prettier-eslint

nealoke commented 6 years ago

@CiGit I guess 👍

nguyennb9 commented 6 years ago

Suddenly I got this bug, before that I didn't update or install anything.

- VSCode Version: Code 1.16.1 (27492b6bf3acb0775d82d2f87b25a93490673c6d, 2017-09-14T16:24:39.530Z)
- OS Version: Darwin x64 16.7.0
- Extensions: 

Extension|Author (truncated)|Version
---|---|---
vscode-wakatime|Wak|1.1.16
project-manager|ale|0.21.1
theme-verdandi|be5|1.6.0
vscode-svgviewer|css|1.4.3
vscode-eslint|dba|1.3.2
githistory|don|0.2.3
json-tools|eri|1.0.2
prettier-vscode|esb|0.24.0
flow-for-vscode|flo|0.7.1
auto-close-tag|for|0.5.1
vscode-icon-theme|jtl|1.5.0
Go|luk|0.6.66

(1 theme extensions excluded)
dcorb commented 6 years ago

@CiGit yes, I have been restarting every time I was changing something. But when I upgraded prettier and prettier-eslint, I noticed also a message from VSCODE: "installation appears to be corrupt", https://code.visualstudio.com/docs/supporting/faq#_installation-appears-to-be-corrupt so I updated to the last VSCode version 1.16.1, (my previous installation was 1 month old) . And then things worked. Sorry it's not very helpful to pinpoint the problem. But I still think the issue was with outdated versions of prettier and prettier-eslint

nealoke commented 6 years ago

@nguyennb9 the extensions auto update so it can be that the extension requires 1.7.x or that in your vscode workspace have a prettier: 1.7.x installed

nguyennb9 commented 6 years ago

@nealoke My team using prettier version 1.1.0, I think I need downgrade this extension to keep it work with prettier 1.1.0

seancheung commented 6 years ago
npm update -D prettier

ctrl+shift+p -> Reload Window

This should work

KATT commented 6 years ago

I only had prettier-eslint-cli in my package.json, this solved it for me:

npm update -D prettier-eslint-cli
tizmagik commented 6 years ago

I got this today, @seancheung workaround worked for me 👍

raviteja83 commented 6 years ago

Try adding this to workspace settings. { "prettier.eslintIntegration": false} This worked for me

CiGit commented 6 years ago

This is definitely a trouble with prettier-eslint.

github-actions[bot] commented 4 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.