Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
How can I use a library in a JS file for my HTML project?

I'm trying to use a lib called ToneJS in my project, in a way that i've could write a button that would apply an reverb effect or increase the pitch of some audio for example.

in my HTML file I'm importing the JS file that is going to have the scripts in a tag

<html>
...
   <script src="tone.js"></script>

and in the tone.js file I have only the import line by now:

import * as Tone from "./node_modules/tone";

but there's my problem: inside the console I got the message: Uncaught SyntaxError: Cannot use import statement outside a module

I tried adding the "type": "module" in the package.json of the project, but nothing happened. Then I changed the type="module" inside the <script> tag inside the HTML file, but another different error appeared:

Failed to load module script: Expected a JavaScript module script but the server responded
with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts
per HTML spec.
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Well, Apparently I was trying to import scripts like in a nodeJS application (using import / require). In one of the comments @sajjadrezaei said that using CDN was an alternative. Then I used <script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.5.44/Tone.js"></script> in my index.html and then I was able to use any of the ToneJS files

about 4 years ago · Juan Pablo Isaza Report

0

If you are using ES6 modules you should use type="module" in your <script> tag so you should use your script tag as below:

<script src="tone.js" type="module"></script>

there is some example here:

<!doctype html>
<html>
<script type="module">
  import * as Tone from "./node_modules/tone";

  //do something with Tone
</script>

You can also use the CDN as an external js file and use Tone.js as below:

<script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.8.38/Tone.js">
about 4 years ago · Juan Pablo Isaza Report

0

If your script is a module, you must do this:

<script src="tone.js" type="module"></script>

Or else the system will think it's normal JavaScript, and that error will occur.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!