Closed daanlenaerts closed 2 weeks ago
Thanks for reporting!
Oh, this is interesting and unexpected. I thought typescript
parser can parse any JS code.
I wonder exactly what code causes the parse error.
I would expect the same, but apparently not.
This is part of the postgres
module, which I was trying out in combination with Drizzle ORM. This is the code for which the error occurs: https://github.com/porsager/postgres/blob/master/src/large.js
I don't see anything special though. Do you?
Would it be an option to revert back to the following, or do you have any arguments against it?
// vite-plugin-rsc-analyze.js
syntax: ext === '.ts' || ext === '.tsx' ? 'typescript' : 'ecmascript',
I'm fine to revert, but we need to understand the exact problem and the reason why typescript
doesn't work.
we could experiment with swc cli.
Totally agree! I have done a quick test by compiling postgres/src/large.js
with the swc cli. It works fine when using the ecmascript
syntax, but the same error surfaces when using the typescript
syntax.
I'm not really sure yet what the reason might be.
➜ waku-test npx swc ./node_modules/postgres/src/large.js
× Expected a semicolon
╭─[node_modules/postgres/src/large.js:4:1]
4 │ return new Promise(async(resolve, reject) => {
5 │ await sql.begin(async sql => {
6 │ let finish
7 │ !oid && ([{ oid }] = await sql`select lo_creat(-1) as oid`)
· ───
8 │ const [{ fd }] = await sql`select lo_open(${ oid }, ${ mode }) as fd`
9 │
10 │ const lo = {
╰────
Caused by:
Syntax Error
Error: Failed to compile 1 file with swc.
at Object.assertCompilationResult (/Users/daan/Downloads/waku-test/node_modules/@swc/cli/lib/swc/util.js:164:15)
at files (/Users/daan/Downloads/waku-test/node_modules/@swc/cli/lib/swc/file.js:205:19)
at async _default (/Users/daan/Downloads/waku-test/node_modules/@swc/cli/lib/swc/file.js:224:9)
Thanks for trying! Can you try with tsc
too? Then, we will know if it's swc issue or TS issue.
I extracted the large.js
file and ran tsc
as follows:
npx tsc ./large.js --allowJs --outDir ./dist
This seems to work fine, no errors reported. When I run npx swc ./large.js
, again with the typescript
syntax, the same error as earlier occurs.
So to me it seems like an issue with swc
, although I don't fully understand why it happens.
I've also gone over the SWC docs on using swc
instead of tsc
, but haven't really found anything that makes a difference there.
Thanks for your investigation.
Let's assume that it's a bug in SWC. I'll open a PR for the workaround.
When building my project with Waku 0.20.1 I get the following error, which I didn't get in Waku 0.20.0. This specifically occurs because of this single line change. When reverting this line to the original implementation, everything builds fine again.
I am not entirely sure why this change was necessary, but I assume there's some good reasoning behind it. Do you have some information on this? I'd love to help figure out a solution.