kaelhem / avrbro

A tool to upload .hex files on Arduino boards with Serial API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

To import the module

Clemenard opened this issue · comments

I tried to run your sample code, but when i run
import avrbro from 'avrbro';
i get some error :
Uncaught TypeError: Failed to resolve module specifier "avrbro". Relative references must start with either "/", "./", or "../".
VSCode give me that hint when i check the problematic line :
Le fichier de déclaration du module 'avrbro' est introuvable. 'c:/wamp64/www/myProject/node_modules/avrbro/dist/avrbro.js' a implicitement un type 'any'. Essayez 'npm install @types/avrbro' s'il existe, ou ajoutez un nouveau fichier de déclaration (.d.ts) contenant 'declare module 'avrbro';',
but theses two solution don't work.

Any idea?

Hello,
to run the sample code, all you need to do is :

  • clone the repo
  • cd into the 'avrbro-master' directory
  • launch a webserver from this point (like https://www.npmjs.com/package/serve for exemple, it's really easy, with this one you just type serve in the terminal)
  • use chrome (because it's chrome only AFAIK) and activate the experimental feature named #enable-experimental-web-platform-features

and it should works.

Let me know if these steps are not working for you.

Edit:
These steps are for running the sample given in the sample directory.
If you want to import avrbro into you project, you need to import it via npm i avrbro --save. Did you do this ?
What's your setup ? I used it in a create-react-app project few months ago, I don't have time right now, but I will check if it works over the week end. Tell me if you have some results...

I aim to use it for https://fr.vittascience.com/arduino, who is coded in javascript+jquery. I encountered that bug while pasting the sample code in my file managing serial api interactions, after using npm i avrbro --save.

I'll try first your steps to run the demo, thanks

OK. If you don't transpile your code with babel or a similar tool, I think you can import the script with old good fashion.
just include it in your html like this:
<script type="text/javascript" src="/node-modules/dist/avrbro.js"></script>

Then avrbro should be available as a global var.

I understand my problem now.
When calling import avrbro from 'avrbro'; it was searching a file ../avrbro/dist/avrbro.js
In your sample.html the path is .. /avrbro/dist/avrbro.m.js
After changing it it works, thanks for the help

Glad to hear that!