Prettier-vscode: vscode-prettier not formatting, can not resolve relative path names

Created on 26 Aug 2019  路  4Comments  路  Source: prettier/prettier-vscode

Summary

When running prettier from vscode, prettier will throw an error.

WARN Error: path should be a path.relative()d string, but got "............\projects\showtime-manager-module\src\lib\features\toolbar\showtime-manager-toolbar.component.ts"

This happens, on save and when calling 'format document'. Running prettier from the command line works just fine.

Steps To Reproduce:

  1. try to format a file inside vscode

Expected result

prettier should format the file.

Actual result

The error as seen above

WARN Error: path should be a path.relative()d string, but got "............\projects\showtime-manager-module\src\lib\features\toolbar\showtime-manager-toolbar.component.ts"
at throwErrror

Additional information

_Feel free to attach a screenshot_.
image

VS Code Version:

version 1.38.0-insider
image

Prettier & Prettier Plugin Version:
esbenp.prettier-vscode: 2.2.1
prettier "version": "1.18.2",

bug locked

Most helpful comment

The problem occurs when the prettierignore file exists within a folder.

I've done a little bit of investigation and created a sample project that reproduces the problem.
prettier-vscode-format-bug.zip

The problem looks to have actually been caused by the recent upgrade to 5.0.0 of the node-ignore package. As per their upgrade docs, a path of the form '../foo' is now considered invalid and throws an error.

When formatting a file, the ignoreFileHandler.ts goes and finds the relative path from the ignore file to the file you're attempting to format. When the prettierignore file is nested inside of some folder, this results in a path like "../file" which is considered invalid by node-ignore and prevents the file from being formatted.

All 4 comments

Any chance you could provide a sample project that I can use to reproduce this? I am not seeing this error on either my windows or mac.

The problem occurs when the prettierignore file exists within a folder.

I've done a little bit of investigation and created a sample project that reproduces the problem.
prettier-vscode-format-bug.zip

The problem looks to have actually been caused by the recent upgrade to 5.0.0 of the node-ignore package. As per their upgrade docs, a path of the form '../foo' is now considered invalid and throws an error.

When formatting a file, the ignoreFileHandler.ts goes and finds the relative path from the ignore file to the file you're attempting to format. When the prettierignore file is nested inside of some folder, this results in a path like "../file" which is considered invalid by node-ignore and prevents the file from being formatted.

We are no longer using node-ignore in version 3.0 (preview). I have tested out the sample repo and it seems to be working as expected now. You can install the preview version here: https://marketplace.visualstudio.com/items?itemName=Prettier.prettier-vscode

If you are still seeing this issue, please reopen.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bajtos picture bajtos  路  4Comments

sebastijandumancic picture sebastijandumancic  路  4Comments

bluemoehre picture bluemoehre  路  3Comments

Tanmccuin picture Tanmccuin  路  3Comments

FlorianWendelborn picture FlorianWendelborn  路  3Comments