Skip to content

[Question] Crashing on build command due to TypeScript annotations reported as Syntax Errors? #621

Description

@goustaff

Hello,

I tried to follow the Matt Pocock's video on preconstruct: https://www.totaltypescript.com/tips/get-a-typescript-package-ready-for-release-to-npm-in-under-2-minutes


Terminal input and output:

❯ pn pub

> [email protected] prepub /home/me/Delivery/damerau-levenshtein
> pnpm build


> [email protected] prebuild /home/me/Delivery/damerau-levenshtein
> tsc --project tsconfig.json && preconstruct fix

🎁 success project already valid!

> [email protected] build /home/me/Delivery/damerau-levenshtein
> preconstruct build

🎁 info building bundles!
🎁 error SyntaxError: /home/me/Delivery/damerau-levenshtein/src/index.ts: Unexpected token, expected "," (1:30)
🎁 error
🎁 error > 1 | function damerauLevenshtein(s1: string, s2: string): number {
🎁 error     |                               ^
🎁 error   2 |   if (s1 === s2) return 0;
🎁 error   3 |
🎁 error   4 |   const [s1len, s2len] = [s1.length, s2.length];
🎁 info If you want to learn more about the above error, check https://preconstruct.tools/errors
🎁 info If the error is not there and you want to learn more about it, open an issue at https://github.com/preconstruct/preconstruct/issues/new
 ELIFECYCLE  Command failed with exit code 1.

Question:

I don't understand the unexpected token Syntax Error message, just due to TypeScript annotations?
Is preconstruct incompatible with TypeScript? It doesn't seem so.


Work-around attempts:

I also tried to add a prebuild script in my package.json, using tsc before calling preconstruct

"prebuild": "tsc --project tsconfig.json && preconstruct fix",

(It seems pointless to call tsc, I just tried to experiment, but I'm still having the same error message.)


Minimal reproduction repository:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions