Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Compiling using --profile=release leads to runtime errors #1514

Closed
xvw opened this issue Oct 3, 2023 · 3 comments · Fixed by #1515
Closed

[BUG] Compiling using --profile=release leads to runtime errors #1514

xvw opened this issue Oct 3, 2023 · 3 comments · Fixed by #1515
Labels

Comments

@xvw
Copy link
Contributor

xvw commented Oct 3, 2023

Describe the bug
At @funkywork, we're working on a collection of tools to interact with Tezos. We recently realized that when using our libraries, producing JavaScript artifacts with the release profile generates incorrect JavaScript output. For example, in this project (I think it's pretty minimal): https://github.com/funkywork/tezos-dapps-examples/tree/main.
Using dune build; dune exec bin/server/dapps.exe and going to http://localhost:8888/dapps/connect launch properly the apps. But if you run dune build --profile=release; dune exec bin/server/dapps.exe you will have an error console:

12:10:45.847 Uncaught SyntaxError: missing ) after argument list client.bc.js:4635
12:10:45.848 Uncaught ReferenceError: nightmare_js is not defined
    <anonymous> http://localhost:8888/dapps/connect:2
connect:2:358
12:10:45.848 Uncaught ReferenceError: nightmare_js is not defined
    <anonymous> http://localhost:8888/dapps/connect:2
connect:2:465

And here is the client.bc.js generated: https://gist.githubusercontent.com/xvw/d679d490d085e671f926e106cfff37b5/raw/69c2c552065c0466a93a4c05b323ccf75c6ef01a/client.bc.js

From a development point of view, this isn't a problem, but it does make it difficult to put things into production, as the non-release bundle weighs in at ~16mb, compared with ~2mb for release.

If I can provide any additional information, or create a smaller example, please don't hesitate to ask!

Versions

  • ocaml: 5.0.0
  • js_of_ocaml: 5.4.0+git-e0d000e-dirty
@xvw xvw added the bug label Oct 3, 2023
@hhugo
Copy link
Member

hhugo commented Oct 3, 2023

There seem to be an issue with the printing of some es6 construct. Can you list all the js files that your bundle in your app ?

@vouillon
Copy link
Member

vouillon commented Oct 3, 2023

The issue is a newline right after an async keyword.
We need to check that we follow the rules in this section: https://tc39.es/ecma262/#sec-rules-of-automatic-semicolon-insertion

fm=b=>async
a=>new
Uint8Array(await
crypto.subtle.digest(b,a)) [...]

@xvw
Copy link
Contributor Author

xvw commented Oct 3, 2023

There seem to be an issue with the printing of some es6 construct. Can you list all the js files that your bundle in your app ?

It is a little bit hard since we built using NPM, but here are the two bundled files (I guess) :
https://gist.github.com/xvw/fff8e06829a9409be4739fb66f98b164 (i guess the culprit come from https://gist.github.com/xvw/fff8e06829a9409be4739fb66f98b164#file-beacon_stubs-js)

hhugo added a commit that referenced this issue Oct 4, 2023
* The async keyword should not be followed by a newline

Fixes #1514

* more fix for async

* Changes

---------

Co-authored-by: Hugo Heuzard <hugo.heuzard@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants