I've been attempting to integrate the mammoth npm library with my Meteor project.
When using the import command, import { mammoth } from "mammoth";, I encountered
Uncaught TypeError: Cannot read property 'bind' of undefined
After trying the command, declare var mammoth: any;, I faced
EXCEPTION: mammoth is not defined
The code snippet I'm using is as follows:
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);
}
Upon using the import
declare var mammoth: any;
I encountered the error:
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)
Upon using the import
import { mammoth } from "mammoth";
I encountered the error:
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
Can anyone provide assistance with this issue?
P.S.: The mammoth library works correctly in an Angular project. The problem arises when attempting to use it in an Angular-Meteor project.