【发布时间】:2016-10-10 21:10:03
【问题描述】:
我正在尝试在 Meteor 应用程序中使用 Seriously.js 库 (https://github.com/brianchirls/Seriously.js/)。我已将该库放在我的流星应用程序的 /imports 文件夹中,并且我正在从整个函数最顶部的 Serious.js 中导出一个变量 Seriously:
export var Seriously = (function (root, factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define('seriously', function () {
var Seriously = factory(root);
if (!root.Seriously) {
root.Seriously = Seriously;
}
return Seriously;
});
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// like Node.
module.exports = factory(root);
.
.
.
etc.
Seriously.js 代码的其余部分是相同的。然后,在客户端脚本中,我这样导入:
import {Seriously} from '/imports/seriously/seriously.js';
然后我有客户端代码。但是,在运行代码时,浏览器会抛出这个错误:
meteor.js?hash=ae8b8af…:930 Exception from Tracker afterFlush function:
2016-06-09 21:30:19.486 meteor.js?hash=ae8b8af…:930 TypeError: _seriously.Seriously is not a constructor
引用了我的这部分代码:
var seriously = new Seriously();
并在流星中编译:
var seriously = new _seriously.Seriously();
我尝试了各种方法将 Seriously 类导出到流星中,但似乎没有任何效果,我遇到了同样的错误。有什么办法可以将此库正确导入流星?
【问题讨论】:
-
为了记录,全新的流星应用程序也会发生这种情况。我感觉我没有正确构建对象,但我不知道如何正确导出库。将 Seriously.js 放入 /client/lib 文件夹并从我的客户端脚本中引用它会导致找不到它。当我遇到另一个库的问题时,将其移至 /imports 文件夹,将其作为变量导出,然后以类似的方式将其导入客户端。
标签: javascript node.js oop meteor html5-video