1

This question relates to my earlier question.

Trying to use howler.js (https://github.com/goldfire/howler.js#documentation) in a Controller.

There is no addon for Howler but it exists as a npm package.

I've followed the instructions to use ember-browserify and then started the ember dev server (ember s).

The import looks like this :

import Howl from "npm:howler";

I've also tried this :

import {Howl as Howl} from "npm:howler" ;

and this :

import {Howl} from "npm:howler" ;

In all cases when I attempt to make use of Howler like this :

var sound = new Howl({
    src: ['https://example.com/foo.mp3']
});
sound.play();

I get an error in the console (first import shown above) :

Uncaught TypeError: _npmHowler.default is not a constructor

or (second and third import shown above) :

Uncaught TypeError: _npmHowler.Howl is not a constructor

The example code for Howler is here and as far as I can see what I'm doing is in line with those examples.

Any suggestions welcome.


FWIW: this is the same body of code as is mentioned here but since that question I've moved onto using ember-browserify


EDIT: This question has been tagged as "possibly a duplicate" of How to use third party npm packages with ember cli app . On closer examination I think it's clear that is not the case. The cited question does not mention the specific error message that I mention in my question , "...is not a constructor", neither does the OP of that question use ember-browserify, which is an integral part of my question.

glaucon
  • 8,112
  • 9
  • 41
  • 63
  • Possible duplicate of [How to use third party npm packages with ember cli app](https://stackoverflow.com/questions/26544578/how-to-use-third-party-npm-packages-with-ember-cli-app) – Jacob van Lingen Apr 30 '18 at 12:47

1 Answers1

5

Howler probably exports more than the constructor function, so you need to make sure you are accessing that part of the module:

import howler from ‘npm:howler’;

let sound = new howler.Howl(...)
handlebears
  • 2,168
  • 8
  • 18