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

"No parser could be inferred" error when i try to commit #52

Closed
o-t-w opened this issue Mar 27, 2023 · 3 comments
Closed

"No parser could be inferred" error when i try to commit #52

o-t-w opened this issue Mar 27, 2023 · 3 comments

Comments

@o-t-w
Copy link

o-t-w commented Mar 27, 2023

In my public directory I have an image file called logosquare.png.
When I try to do a git commit I get the following error:

Preparing lint-staged...
❯ Running tasks for staged files...
  ❯ package.json — 2 files
    ❯ * — 2 files
      ✖ prettier --plugin-search-dir=. --write [FAILED]
↓ Skipped because of errors from tasks. [SKIPPED]
✔ Reverting to original state because of errors...
✔ Cleaning up temporary files...

✖ prettier --plugin-search-dir=. --write:
[error] No parser could be inferred for file: public/logosquare.png
src/content/blog/submitter-formdata.md 217ms
husky - pre-commit hook exited with code 1 (error)

Also it's not well documented how to add images for a blog post.

@o-t-w
Copy link
Author

o-t-w commented Apr 1, 2023

I am still getting this error
Screenshot 2023-04-01 at 15 09 33

@floatingpurr
Copy link
Contributor

The error is triggered by Prettier that is following these rules:

# Ignore everything
/*
# Except these files & folders
!/src
!/public
!/.github
!tsconfig.json
!astro.config.mjs
!package.json
!.prettierrc
!.eslintrc.js
!README.md

Prettier is triggered upon commit by a pre-commit hook:

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx lint-staged

A simple way to get rid of that, preserving the hook, is adding *.png to your .prettierignore.

@satnaing
Copy link
Owner

Hello,
First of all, sorry for being late to resolve this issue. I've been busy for some time and couldn't focus on my open-source projects for a while.

In AstroPaper, lint-staged is triggered whenever we try to commit. Lint-staged is then configured to format (with prettier) the staged files. The error occurs because lint-staged is trying to format the staged logosquare.png which is obviously not a file to get formatted.

To resolve this issue, we can try a few ways

1) Disable lint-staged for a while when committing

We can disable lint-staged for a while by commenting out npx lint-staged inside .husky/pre-commit file. This is the easiest workaround for this kind of issue_ though this is not the real solution.

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# npx lint-staged

2) Ignore public directory in prettier

We can ignore the entire public directory, where the new logosquare.png exists, in prettier. By doing so, this issue is resolves although other files like toggle-theme.js and other codes won't be formatted in the future. So, this approach is also not recommended.

3) Update lint-staged config in package.json file (Recommended)

We can format everything except images like png, jpg, webp etc in lint-staged config inside package.json. This should solve the similar problems like this in the future, and thus, this method is recommended.

Before

  "lint-staged": {
    "*": [
      "prettier --plugin-search-dir=. --write"
    ]
  }

After

  "lint-staged": {
    "!(*.{png,jpg,jpeg,webp})": [
      "prettier --plugin-search-dir=. --write"
    ]
  }

Hope this helps you in some way. I'll try to make a PR for this issue too. If you still have some problems, plz let me know. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants