【发布时间】:2017-11-24 07:55:41
【问题描述】:
我正在尝试将庞大的 npm 库与流星集成。
使用导入命令时, import { mammoth } from "mammoth"; 越来越
未捕获的类型错误:无法读取未定义的属性“绑定”
使用命令时, declare var mammoth: any; 越来越
例外:未定义猛犸象
我使用的代码是
this.readFileInputEventAsArrayBuffer(event, function(arrayBuffer) {
mammoth
.convertToHtml({ arrayBuffer: arrayBuffer })
.then(function(result: any) {
var html = result.value; // The generated HTML
var messages = result.messages; // Any messages, such as warnings during conversion
// console.log('html: ' + html);
document.getElementById("output").innerHTML = html;
var elements = document.getElementById("output").children;
console.log(elements);
console.log(JSON.stringify(elements));
console.log(elements.length);
for (var i = 0; i < elements.length; i++) {
console.log(i + " --- ");
console.log(elements[i]);
var data = elements[i].innerHTML;
// elements[i].setAttribute("draggable","true");
}
})
.done();
console.log(
"event in fileUpload-readFileInputEventAsArrayBuffer" + event
);
});
readFileInputEventAsArrayBuffer(event, callback) {
var file = event.target.files[0];
var reader = new FileReader();
reader.onload = function(loadEvent: any) {
var arrayBuffer = loadEvent.target.result;
console.log("arrayBuffer: ");
console.log(arrayBuffer);
callback(arrayBuffer);
};
reader.readAsArrayBuffer(file);
}
使用导入时
声明 var mammoth: any;
得到错误
ReferenceError: mammoth is not defined
at app.component.ts:75
at FileReader.reader.onload (app.component.ts:109)
at ZoneDelegate.invoke (modules.js:22723)
at Object.onInvoke (modules.js:57096)
at ZoneDelegate.invoke (modules.js:22722)
at Zone.runGuarded (modules.js:22607)
at FileReader.<anonymous> (modules.js:22585)
Uncaught ReferenceError: mammoth is not defined
at app.component.ts:75
at FileReader.reader.onload (app.component.ts:109)
at ZoneDelegate.invoke (modules.js:22723)
at Object.onInvoke (modules.js:57096)
at ZoneDelegate.invoke (modules.js:22722)
at Zone.runGuarded (modules.js:22607)
at FileReader.<anonymous> (modules.js:22585)
使用导入时
从“猛犸象”导入 { mammoth };
得到错误
Uncaught TypeError: Cannot read property 'bind' of undefined
at meteorInstall.node_modules.mammoth.lib.docx.files.js (modules.js?hash=cd1f432…:83272)
at fileEvaluate (modules-runtime.js?hash=637cb12…:191)
at require (modules-runtime.js?hash=637cb12…:116)
at meteorInstall.node_modules.mammoth.lib.docx.docx-reader.js (modules.js?hash=cd1f432…:82091)
at fileEvaluate (modules-runtime.js?hash=637cb12…:191)
at require (modules-runtime.js?hash=637cb12…:116)
at meteorInstall.node_modules.mammoth.lib.index.js (modules.js?hash=cd1f432…:81954)
at fileEvaluate (modules-runtime.js?hash=637cb12…:191)
at require (modules-runtime.js?hash=637cb12…:116)
at meteorInstall.client.imports.app.app.component.js (app.component.ts:12)
at fileEvaluate (modules-runtime.js?hash=637cb12…:191)
at require (modules-runtime.js?hash=637cb12…:116)
at meteorInstall.client.imports.app.index.js (index.ts:1)
at fileEvaluate (modules-runtime.js?hash=637cb12…:191)
at require (modules-runtime.js?hash=637cb12…:116)
at meteorInstall.client.main.js (main.ts:5)
at fileEvaluate (modules-runtime.js?hash=637cb12…:191)
at require (modules-runtime.js?hash=637cb12…:116)
at demo.collection.ts:4
请帮忙。
P.S.:作为 Angular 项目运行时,它运行良好。面对 问题,在 angular-meteor 项目中进行时。
【问题讨论】:
-
您如何将庞大的库导入您的页面?
-
试试
import mammoth from "mammoth";? -
@Alex,当我使用它导入时,得到这个 Uncaught TypeError: Cannot read property 'bind' of undefined。我的疑问是流星是否支持猛犸象库的集成/使用?
-
请注意我的示例中没有
{和} -
@Raven,我正在通过尝试以下操作导入庞大的库,
import { mammoth } from "mammoth"; import mammoth from "mammoth"; declare var mammoth: any; var mammoth = require("mammoth");
标签: javascript meteor npm node-modules mammoth