Decorators problem for Angular project.
See original GitHub issueHello,
I tried to use the plugin in the Angular project and got this error:
> prettier --write src/app/app.component.ts --config ./.prettierrc
src\app\app.component.ts
[error] src\app\app.component.ts: SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): 'decorators-legacy, decorators' (5:0)
[error] 1 | import { isEmpty } from "lodash-es";
[error] 2 |
[error] 3 | import { Component } from "@angular/core";
[error] 4 |
[error] 5 | @Component({
[error] 6 | selector: "app-root",
[error] 7 | templateUrl: "./app.component.html",
[error] 8 | styleUrls: ["./app.component.css"]
[error] 9 | })
[error] 10 | export class AppComponent {
[error] 11 | title = "ng-prettier";
[error] 12 |
[error] 13 | get text(): string {
[error] 14 | return isEmpty(this.title) ? "" : this.title;
[error] 15 | }
[error] 16 | }
[error] 17 |
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! ng-prettier@0.0.0 format: `prettier --write src/app/app.component.ts --config ./.prettierrc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the ng-prettier@0.0.0 format script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
I use:
- Prettier: 2.2.0
- Angular: 11.0.2
- Typescript: 4.0.5
- Plugin version: 1.3.0
What am I doing wrong? Is there any workaround?
Thanks a lot.
NOTE: No problem with React.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Decorators do not work as you might expect
Decorators are great. They allow us to add annotations and a meta-programming syntax for class declarations and members, including properties, ...
Read more >Decorators error in VS code editor after upgrading to Angular 10
If you created some file and define some class with decorator but didn't import it in any included in compilation file then you...
Read more >Missing @Directive()/@Component() decorator migration
This migration adds an empty @Directive() decorator to undecorated base classes that: Use Angular features; Are extended by directives or components.
Read more >Solving AOT Error in NgRx: Function calls are not supported in ...
However when you build the Angular project using prod mode (AOT by default) ng build --prod, you will run into an error like:...
Read more >What are the differences between an Annotation and a ...
Decorators are predefined in AngularJs. · Decorators are used by TypeScript compiler. · Decorators are used to attach metadata to a class,objects ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

With the release of v2.0.1, this should be fixed. Either prettier will figure out the syntax correctly, or you can use
experimentalBabelParserPluginsListin your.prettierrcto pass the correct parser name.If there was still problems, you can of course re-open this issue.
@byara, you are right. After adding
"parser": "angular"to the.prettierrcthe command executed with no error. This is my.prettierrcfile:Nevertheless, now I have another problem… Formatted code looks like this:
This looks not really prettiery… 😄