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: Handlebars partials are not supported #11834

Open
itssabhishek opened this issue Nov 19, 2021 · 30 comments
Open

SyntaxError: Handlebars partials are not supported #11834

itssabhishek opened this issue Nov 19, 2021 · 30 comments
Labels
lang:handlebars Issues affecting Handlebars (Glimmer) type:enhancement A potential new feature to be added, or an improvement to how we print something

Comments

@itssabhishek
Copy link

itssabhishek commented Nov 19, 2021

Prettier 2.4.1

Handlebars files are not getting formatted when included partials. I searched it on google but no proper solution was found. Please fix this.

Edited by maintainer:

Prettier 3.0.3
Playground link

--parser glimmer
--trailing-comma es5

Input:

{{> header}}

Output:

SyntaxError: Handlebars partials are not supported (1:0)
> 1 | {{> header}}
    | ^^^^^^^^^^^^
@sosukesuzuki
Copy link
Member

Can you use issue template?

@sosukesuzuki sosukesuzuki added the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Nov 20, 2021
@itssabhishek
Copy link
Author

Yes I can use template. It is parsing with no problem.

@no-response no-response bot removed the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Nov 20, 2021
@sosukesuzuki
Copy link
Member

sosukesuzuki commented Nov 20, 2021

Can you reproduce the bug at https://prettier.io/playground/ ?

@itssabhishek
Copy link
Author

Definitely but I am in India and its kind of late night here. Will it be okay if I perform this tomorrow morning and then inform you?

@itssabhishek
Copy link
Author

By the way you can also try this by taking any handlebar partial in your file

@sosukesuzuki
Copy link
Member

To be honest, I know very little about Handlebars. So it's costly to try it in my own environment. It would be helpful if you could share the results on Playground.

@sosukesuzuki sosukesuzuki added the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Nov 21, 2021
@itssabhishek
Copy link
Author

itssabhishek commented Nov 21, 2021

SyntaxError: Unexpected token (1:3)

1 | {{> header}}
| ^
2 |
3 |
4 |

This is what i am getting in playground

@itssabhishek
Copy link
Author

SyntaxError: Unexpected token (1:3)

1 | {{> header}}
| ^
2 |
3 |
4 |

@no-response no-response bot removed the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Nov 21, 2021
@sosukesuzuki
Copy link
Member

sosukesuzuki commented Nov 21, 2021

Thank you. Prettier doesn't support Handlebars partials

Prettier 2.4.1
Playground link

--parser glimmer

Input:

{{> header}}

Output:

SyntaxError: Handlebars partials are not supported: 

|
|  {{> header}}
|

(error occurred in 'an unknown module' @ line 1 : column 0) (1:0)
> 1 | {{> header}}
    | ^^^^^^^^^^^^

@itssabhishek
Copy link
Author

Then how we can solve this issue?

@sosukesuzuki
Copy link
Member

Sorry, I don't know. I'll investigate.

@sosukesuzuki sosukesuzuki added lang:handlebars Issues affecting Handlebars (Glimmer) status:needs investigation Issues that need additional investigation, e.g. to understand whether the reported behavior is a bug labels Nov 25, 2021
@itssabhishek
Copy link
Author

I think we have to add this feature.

phineasla added a commit to phineasla-hcmus/3.1-Web-Online-Auction that referenced this issue Dec 16, 2021
@eimantaaas
Copy link

Any news to this?

@itssabhishek
Copy link
Author

No

@duailibe
Copy link
Member

duailibe commented Feb 2, 2022

FYI we use the Glimmer parser that does the parsing of code that combines Handlebars + HTML (the Handlebars parser doesn't support HTML), but that parser does not support all Handlebars features (e.g. partials)

That means we're blocked until the Glimmer parser support those features or somebody comes up with another solution.

nicolasrouanne added a commit to nicolasrouanne/ghost-pacific that referenced this issue Sep 3, 2022
- handlebar partials are not yet supported by prettier, so removing files with errors
- prettier/prettier#11834
@Th3S4mur41
Copy link

@duailibe is there an issue to have support for this be added to Glimmer?
I couldn't find one.

@devbytyler
Copy link

Any progress on this?

@ahilke
Copy link

ahilke commented Mar 20, 2023

@duailibe is there an issue to have support for this be added to Glimmer?
I couldn't find one.

@Th3S4mur41 I don't think there are any concrete plans, since Glimmer is supporting Ember's style of Handlebars and not Handlebars generally. I see an attempt was made here though: glimmerjs/glimmer-vm#1367

@lenovouser
Copy link

I would also really like to see this being fixed 👍🏻 Is there any way one can help?

@deurk
Copy link

deurk commented Apr 21, 2023

Seem unlikely at this point. Would there be any way to just avoid triggering an error and being able to just ignore those lines??

@rserbitar
Copy link

bummer

@baileymatthewr
Copy link

baileymatthewr commented Jul 19, 2023

@sosukesuzuki && @itssabhishek : It seems like a meet-you-halfway-solution would be to allow comments that prevent the parser from touching that bit of code. However, it still tries to "validate" and gives that error.

Example:

{{#if edit}}
  <form id='item-form-0' class='needs-validation edit-item' novalidate>
    {{!-- prettier-ignore-start --}}
      {{> p_shop_ticket_product_info }}
    {{!-- prettier-ignore-end --}}
  </form>
{{else}}

However, not even that works. it still produces that error...

@SitaGomes
Copy link

There is a prettierrc configuration that formats the partials the right way

For more details see shpp/programming.org.ua#25

filename: .prettierrc.json

content:

{
  "trailingComma": "all",
  "tabWidth": 2,
  "semi": false,
  "singleQuote": true,
  "printWidth": 100,
  "useTabs": false,
  "bracketSpacing": true,
  "endOfLine": "lf",
  "arrowParens": "always",
// IMPORTANT PART BELLOW
  "overrides": [   
    {
      "files": "**/*.hbs",
      "options": {
        "parser": "angular"   
      }
    }
  ]
}

@bshifrin
Copy link

bshifrin commented Sep 5, 2023

@SitaGomes it works for partials, but doesn't work with conditions for attributes:

components/video-playlist/template.hbs
[error] components/video-playlist/template.hbs: SyntaxError: Unexpected closing tag "div". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (2:1)
[error]   1 | <div {{#if gridEnabled}}data-items-layout="list"{{/if}}>
[error] > 2 | </div>
[error]     | ^^^^^^
[error]   3 |

Any ideas how to parse and format them correctly?

mgeisler added a commit to google/comprehensive-rust that referenced this issue Sep 28, 2023
Initially, I also formatted the templates in `theme/`, but this
triggers prettier/prettier#11834. So I
exclude them for now.
mingyc added a commit to google/comprehensive-rust that referenced this issue Oct 2, 2023
Initially, I also formatted the templates in `theme/`, but this triggers
prettier/prettier#11834. So I exclude them for
now.

---------

Co-authored-by: Ming-Ying Chung <mych@chromium.org>
@emilienbidet
Copy link

Any news or workaround about using Prettier with Handlebars partials?

@sosukesuzuki sosukesuzuki added type:enhancement A potential new feature to be added, or an improvement to how we print something and removed status:needs investigation Issues that need additional investigation, e.g. to understand whether the reported behavior is a bug labels Oct 8, 2023
@xianping-yan
Copy link

??? resolved this issue?

@p4535992
Copy link

p4535992 commented Mar 5, 2024

@SitaGomes it works for partials, but doesn't work with conditions for attributes:

components/video-playlist/template.hbs
[error] components/video-playlist/template.hbs: SyntaxError: Unexpected closing tag "div". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (2:1)
[error]   1 | <div {{#if gridEnabled}}data-items-layout="list"{{/if}}>
[error] > 2 | </div>
[error]     | ^^^^^^
[error]   3 |

Any ideas how to parse and format them correctly?

did you find a workaround ?

@bshifrin
Copy link

bshifrin commented Mar 6, 2024

did you find a workaround ?

@SitaGomes nope

@Lino99-FE
Copy link

Lino99-FE commented Apr 3, 2024

#11834 (comment)
I think his solution is very good. As long as it can effectively ignore part of the code, it can avoid many problems caused by syntax incompatibility.
But when can we support partial ignoring?

@trylovetom
Copy link

Any update? I can't ignore code either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang:handlebars Issues affecting Handlebars (Glimmer) type:enhancement A potential new feature to be added, or an improvement to how we print something
Projects
None yet
Development

Successfully merging a pull request may close this issue.