1

I am trying to create a Word to HTML converter, and I am trying to use Mammoth as a framework. Whenever I run my script, I get:

Internal/modules/cjs/loader.js:983
  throw err;
  ^

Error: Cannot find module 'mammoth'
Require stack:
- C:\Users\magnu\OneDrive\Documents\GitHub\work_app\app.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
    at Function.Module._load (internal/modules/cjs/loader.js:862:27)
    at Module.require (internal/modules/cjs/loader.js:1042:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (C:\Users\magnu\OneDrive\Documents\GitHub\work_app\app.js:4:15)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'C:\\Users\\magnu\\OneDrive\\Documents\\GitHub\\work_app\\app.js' ]
}

This is the code for my app.js

// Requirements
var express = require('express'),
    ejs = require('ejs'),
    mammoth = require('mammoth')
var app = express();
app.set('view engine', 'ejs');


// Mammoth

mammoth.convertToHtml({path: "../../../../Downloads/Federal Gov't - Debate Sheet.docx"})
    .then(function(result){
        var html = result.value; // The generated HTML
        var messages = result.messages; // Any messages, such as warnings during conversion
    })
    .done();

app.get('/', function (req, res) {
    res.render('landing');
})
app.listen(4009, function () {
    console.log("Server ready on PORT 4009");
})

If anyone knows the solution to my problem, please post below.

For all of my code, go to Github

1 Answers1

-1

The answer to this is very simple. Just make sure you have installed the package.

  • But I am sure I have already installed the package. What now?

My next course of action is to make sure you have it under dependencies in the package.json file you store other dependencies in. To automate this process, create a GitHub page and start commiting to it. This can speed up your development process by months simply because other people are able to help you.

If those don't work, ask a question and comment it to me and I might be able to help!