Open PaulLeCam opened 4 years ago
Hey @PaulLeCam what version of denopack are you using? Could you share your denopack config? I'm not 100% certain, but I think the issue isn't necessarily the fact that it's using WASM, so I'd like to investigate it further.
Yes WASM is my assumption but that might be something else, this was just the most obvious difference I found between std/hash
and other std
libraries.
Here is a simple way I could reproduce the issue (I'm using Deno 1.3.0):
File test.ts
:
export { createHash } from 'https://deno.land/std@0.65.0/hash/mod.ts'
And running:
deno run --unstable --allow-env --allow-net --allow-read --allow-write https://deno.land/x/denopack@0.5.0/cli.ts bundle -i test.ts
@PaulLeCam I have some good news and bad news: the good news is that as far as I know, this is not related to WASM, and I'm fairly certain bundling WASM should work. the bad news however is that this is related to the fact that Terser does not support top level awaits yet and this is used inside of the implementation of std/hash.
https://deno.land/std@0.65.0/hash/_wasm/hash.ts {
error: SyntaxError: Unexpected await identifier inside strict mode
I will leave this issue open as this is fairly annoying to anyone wanting to use std/hash
Thanks for investigating!
Too bad about Terser, I guess it's even a larger problem than std/hash
because any module could possibly user a top-level await
.
Yep, I'm thinking of a good way to support this going forward. I think I might need to change the Terser plugin back to minifying the bundle chunks instead of as a transform hook or something similar. Will test some approaches this week after I finished up the plugins I've been working on 😄
Thanks for renaming the issue btw 👍
I think I fixed this in a terser update a few weeks ago.
Does Terser 5 support TLA now?
I think that is why I updated it in the first place... can't remember now though. I'll check real quick.
Oh never mind - I updated because optional chaining... so this is not fixed yet.
Yeah I just checked and the issue regarding awaits on Terser's github is still open :c sucks but we'll keep an eye out on it ;)
Hey, thanks for this project, it looks like a great way to bring nice Deno code to the browser!
Is your feature request related to a problem? Please describe.
I'd like to use denopack to bundle any deno
std
library not using theDeno
APIs.I tried bundling a project but it fails with
Uncaught Error: Terser is not supposed to return nothing!
. I narrowed down the problem to havingexport { createHash } from 'https://deno.land/std@0.65.0/hash/mod.ts'
in mydeps.ts
file and my assumption, comparing with other imports fromstd
that can get compiled correctly, is that it's because thestd/hash
module uses WASM imports.Describe the solution you'd like
Rollup has a WASM plugin that would be great to support in denopack, either as a plugin or in core. Alternatively, if there is an easy way to convert/wrap existing Rollup plugins to denopack ones it could be a good option.
Describe alternatives you've considered
Using
deno bundle
+ minifierThanks!