espressif / esptool-js

Javascript implementation of flasher tool for Espressif chips, running in web browser using WebSerial.
https://espressif.github.io/esptool-js/
Apache License 2.0
251 stars 101 forks source link

Browser module imports don't work #124

Closed elite174 closed 5 months ago

elite174 commented 6 months ago

image

I'm trying to use this lib in the browser without compilation and get this error.

elite174 commented 6 months ago

try the following code to reproduce

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script type="module">
      import json from "https://unpkg.com/esptool-js@0.3.2/lib/targets/esp32.js?module";
    </script>
  </body>
</html>
elite174 commented 6 months ago

I guess the reason for this this line: import ESP32_STUB from "./stub_flasher/stub_flasher_32.json?module"; The point is that you don't need to use ?module for json files

elite174 commented 6 months ago

@brianignacio5 Could you fix this please?

brianignacio5 commented 5 months ago

How about using the resulting bundle file : https://unpkg.com/esptool-js@0.3.2/bundle.js ?

elite174 commented 5 months ago

Yes, that would work. But anyways, it's better be fixed

elite174 commented 5 months ago

Also you need to update README then, because it recommends using https://unpkg.com/esptool-js/lib/index.js?module

brianignacio5 commented 5 months ago

I think is also the fact that ?module is also experimental and probably not be used.

For example using https://unpkg.com/esptool-js@0.3.2/lib/targets/stub_flasher/stub_flasher_32.json seems to work. Maybe we remove ?module from readme and add bundle.js too.