Prettier-atom: "Cannot read property 'sync' of undefined" on projects without Prettier config

Created on 9 Apr 2018  路  11Comments  路  Source: prettier/prettier-atom

I'm receiving the following error every time I save a file in projects which don't have a Prettier config file. I have to disable "Format On Save" to avoid error notifications popping up every time I save a file.

error

I don't have this issue when editing files in projects which contain a Prettier config file.

troubleshooting

Most helpful comment

I'm pretty sure. I'll re-enable the package now and take a screenshot the next time it pops up.

All 11 comments

@cbovis it could be that your version of prettier-atom is so old that the bundled version doesn't have resolveConfig.sync defined yet.

Can you try updating prettier-atom, then restarting Atom, and see if that fixes it?

I'm getting the exact same issue - the error keeps popping up for me on projects that don't have a Prettier config file. In my case I opted to just disable prettier-atom altogether to make the message go away.

I'm running the latest version of Prettier (0.53.0). Let me know if there's anything I can do to help you troubleshoot this.

@callmeaponte Are you sure it's that exact same error?

I'm pretty sure. I'll re-enable the package now and take a screenshot the next time it pops up.

It finally popped up again, here's a screenshot:

screen shot 2018-06-16 at 12 22 23 pm

@callmeaponte This is a very common error for people who are using an old version of prettier. Can you verify what version of Prettier is in your node_modules folder in the project where this is occurring by checking the package.json inside of node_modules/prettier?

Prettier doesn't exist in the node_modules folder (it's not a dependency), nor is it installed globally.

In case you want to try and reproduce it - this is occurring on a brand new Angular app spun up using the ng new CLI command. I'm using prettier-atom version 0.54.0.

For what it's worth, opening the console, clicking the line indicator at the top of the error, and making the following code change got things working for me.

const getPrettierConfigOptions = _.cond([[_.flow(getCurrentFilePath, isDefined), editor => {
  // $FlowFixMe
  const hasResolveConfigSync = isDefined(getPrettierInstance(editor).resolveConfig.sync);
  if (!hasResolveConfigSync) return null;

became

const getPrettierConfigOptions = _.cond([[_.flow(getCurrentFilePath, isDefined), editor => {
  // $FlowFixMe
  const hasResolveConfigSync = isDefined(getPrettierInstance(editor).resolveConfig && getPrettierInstance(editor).resolveConfig.sync);
  if (!hasResolveConfigSync) return null;

I'm not sure why that variable wouldn't exist (I didn't really dig into the code), but I'm on 0.54.0. Additionally, adding a prettier config and restarting atom didn't seem to get it working. Hopefully this is a functional workaround for other people until the root cause is found.

Would it be okay to open up a pull request with the change suggested by @Blink18260000 as a temporary workaround for now?

@callmeaponte I'm about to release #404 which makes a change that makes this no longer relevant so I think I'm just going to release that as a fix.

Awesome. Thank you!

Was this page helpful?
0 / 5 - 0 ratings