javascriptexpressnpmnpm-installtonejs

Getting references error when importing tone.js


I have a basic express.js server setup on my Mac. To this I'm trying to import Tone.js, https://tonejs.github.io, by following the instructions.

npm install tone

To import Tone.js:

import * as Tone from 'tone'

But I'm getting this error

Uncaught TypeError: Failed to resolve module specifier "tone". Relative references must start with either "/", "./", or "../".

My Package file looks like this

{
  "name": "XXXXX",
  "version": "1.0.0",
  "description": "Run npm start",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon start"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/xxxxx"
  },
  "author": "xxxxx xxxx",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/xxxxxxx"
  },
  "dependencies": {
    "express": "^4.17.1",
    "nodemon": "^2.0.12",
    "tone": "^14.7.77"
  }
}

Solution

  • As @lars-flieger pointed out, it's not possible to run it one a node.js server. I ended up downloading Tones.js from here and includes it as a regular script tag.

    https://github.com/Tonejs/Tone.js/wiki/Installation