question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SyntaxError: Unexpected token, expected "}"

See original GitHub issue
[error] apps/api/src/app/modules/design/template/template.controller.ts: SyntaxError: Unexpected token, expected "}" (60:68)
[error]    1 | import { Body, Controller, HttpService, Post } from "@nestjs/common";
[error]    2 | import { retry } from "rxjs/operators";
[error]    3 |
[error]    4 | import { DesignTemplate, DesignTextElement } from "@diandiantu/design/interfaces";
[error]    5 |
[error]    6 | import { TemplateService } from "../service/template.service";
[error]    7 | import { UpdateTextDao } from "./update-text.dao";
[error]    8 | import { TextRender } from "@diandiantu/design/render";
[error]    9 | import { CanvasKitService } from "../../../thrid-party/canvas-kit/canvas-kit.service";
[error]   10 | import { CanvasKit } from "@design/canvaskit-wasm";
[error]   11 |
[error]   12 | @Controller("/design/template")
[error]   13 | export class TemplateController {
[error]   14 |   requestFile: (url) => Promise<ArrayBuffer>;
[error]   15 |   CanvasKit: CanvasKit;
[error]   16 |
[error]   17 |   constructor(private templateService: TemplateService, private _httpService: HttpService,
[error]   18 |               private _canvaskitService: CanvasKitService) {
[error]   19 |     this.CanvasKit = this._canvaskitService.canvasKit;
[error]   20 |     this.requestFile = (url) => {
[error]   21 |       const req = this._httpService
[error]   22 |         .get<ArrayBuffer>(`http:${url}`, { responseType: "arraybuffer" })
[error]   23 |         .pipe(retry(3))
[error]   24 |         .toPromise();
[error]   25 |       return new Promise<ArrayBuffer>((resolve, reject) => {
[error]   26 |         req
[error]   27 |           .then((resp) => {
[error]   28 |             resolve(resp.data);
[error]   29 |           })
[error]   30 |           .catch(reject);
[error]   31 |       });
[error]   32 |     };
[error]   33 |   }
[error]   34 |
[error]   35 |   @Post("/update_text_height")
[error]   36 |   async update_text_height(@Body() body: UpdateTextDao) {
[error]   37 |     const { template_id, system } = body;
[error]   38 |     let templateData: DesignTemplate;
[error]   39 |     if (system) {
[error]   40 |       templateData = await this.templateService.getSystemTemplateData(template_id);
[error]   41 |     } else {
[error]   42 |       templateData = await this.templateService.getUserTemplateData(template_id);
[error]   43 |     }
[error]   44 |
[error]   45 |     for (const page of templateData) {
[error]   46 |       const pIndex = templateData.indexOf(page);
[error]   47 |       for (const ele of page.elements) {
[error]   48 |         const eIndex = page.elements.indexOf(ele);
[error]   49 |         if (ele.type === "text") {
[error]   50 |           const oldHeight = ele.base.h;
[error]   51 |
[error]   52 |           const provider = await this._canvaskitService.loadProvider();
[error]   53 |           const defaultName = this._canvaskitService.defaultFonts;
[error]   54 |
[error]   55 |           const textProcess = new TextRender(<DesignTextElement>ele, this.CanvasKit, provider, defaultName);
[error]   56 |           await textProcess.render();
[error]   57 |           const newHeight = textProcess.paragraph.getHeight();
[error]   58 |
[error]   59 |           if (newHeight > oldHeight) {
[error]   60 |             templateData[pIndex].elements[eIndex].base.h = newHeight;
[error]   61 |           }
[error]   62 |         }
[error]   63 |       }
[error]   64 |     }
[error]   65 |
[error]   66 |     if (system) {
[error]   67 |       return this.templateService.saveSystemTemplateData(template_id, templateData);
[error]   68 |     } else {
[error]   69 |       return this.templateService.saveUserTemplateData(template_id, templateData);
[error]   70 |     }
[error]   71 |   }
[error]   72 | }
[error]   73 |
[error] libs/design/render/src/page-render.ts: SyntaxError: Unexpected token (169:8)
.
.
.
[error]   161 |   async render() {
[error]   162 |     const bgNode = await this.renderBackground();
[error]   163 |     this.svgTree.children.push(bgNode);
[error]   164 |     const { elements } = this.data;
[error]   165 |     const elePromises = elements.map((element) => {
[error]   166 |       if (element.type === 'svg') {
[error]   167 |         return this.renderSVG(<DesignSVGElement>element);
[error]   168 |       } else if (element.type === 'text') {
[error]   169 |         return this.renderText(<DesignTextElement>element);
[error]   170 |       }
[error]   171 |     });
[error]   172 |     const eleNodes = (await Promise.all(elePromises)).reduce<INode[]>((result, curr) => {
[error]   173 |       if (curr) {
[error]   174 |         result.push(curr);
[error]   175 |       }
[error]   176 |       return result;
[error]   177 |     }, []);
[error]   178 |     this.svgTree.children.push(...eleNodes);
[error]   179 |     return stringify(this.svgTree);
[error]   180 |   }

There are two errors during formatting, and I don’t know why there is an error here. If I remove prettier-plugin-sort-imports without any errors

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:9

github_iconTop GitHub Comments

3reactions
colelawrencecommented, May 31, 2021

I’m seeing the same error (not necessarily the same issue), mine happens when encountering the following:

web_ui/src/test-prettier.ts
[error] web_ui/src/test-prettier.ts: SyntaxError: Unexpected token, expected "}" (2:3)
[error]   1 | const b = <any> {
[error]   2 |   a: 1
[error]   3 | }
[error]   4 |
 ERROR  Command failed with exit code 2.

Similarly:

web_ui/src/test-prettier.ts
[error] web_ui/src/test-prettier.ts: SyntaxError: Unterminated JSX contents (1:18)
[error]   1 | const b = <any> {}
[error]   2 |
 ERROR  Command failed with exit code 2.

It seems related to that <type> cast in TypeScript.

1reaction
byaracommented, Oct 20, 2021

This issue will be resolved in v3. FYI @StringKe @colelawrence

Read more comments on GitHub >

github_iconTop Results From Across the Web

React — Syntax error: Unexpected token, expected
Well, you are getting error because you are defining the function like in a class, not in a function. Use a proper function...
Read more >
Syntax Error: Unexpected token, expected "," (1:22) - MongoDB
Hi guys, I'm pretty new to MongoDB and just starting my journey learning different ways I can query my documents.
Read more >
(syntax error) unexpected token, expected "}" - Replit
I believe this to be a syntax error, but I fail to find where it is. On line 49, there is said to...
Read more >
SyntaxError: Unexpected token, expected ";" (1:7) on MongoDb
SyntaxError : Unexpected token, expected ";" (1:7) on MongoDb. DB-213.6461.19, JRE 11.0.13+7-b1751.21x64 JetBrains s.r.o., OS Mac OS X(aarch64) v12.0.1, ...
Read more >
Select.js: Unexpected token, expected "," (3:32) · Issue #4274 ...
I tried to run the example code but React tells me that there's a syntax error in the library: My code (the example)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found