Emberjs / ember-browserify:“X不是构造函数”? [英] Emberjs / ember-browserify : "X is not a constructor"?
问题描述
此问题与我之前的问题有关。
This question relates to my earlier question.
尝试使用howler.js( https://github.com/goldfire/howler.js#documentation 。
Trying to use howler.js (https://github.com/goldfire/howler.js#documentation) in a Controller.
咆哮没有插件但是它以npm包的形式存在。
There is no addon for Howler but it exists as a npm package.
我跟着使用ember-browserify的说明然后启动了ember dev服务器( ember s
)。
I've followed the instructions to use ember-browserify and then started the ember dev server (ember s
).
导入如下所示:
import fromnpm:howler;
我也试过这个:
从{npm导入{Howl as Howl} :咆哮;
这个:
从npm:howler导入{Howl};
在所有情况下,当我试图像这样使用咆哮时:
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
Howler的示例代码是这里,据我所知,我正在做的是与这些例子一致。
The example code for Howler is here and as far as I can see what I'm doing is in line with those examples.
欢迎任何建议。
FWIW:这与提到的代码体相同在那里但是从那个问题开始我已经开始使用 ember-browserify
FWIW: this is the same body of code as is mentioned here but since that question I've moved onto using ember-browserify
编辑:此问题已被标记为如何使用第三方npm软件包与ember cli应用程序。经过仔细研究,我认为事实并非如此。引用的问题没有提到我在我的问题中提到的具体错误信息,......不是构造函数,该问题的OP也不使用ember-browserify,这是我的问题的一个组成部分。
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.
推荐答案
咆哮可能导出的不仅仅是构造函数,所以你需要确保访问模块的那一部分: / p>
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(...)
这篇关于Emberjs / ember-browserify:“X不是构造函数”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!