Home > Mobile >  Object has no method 'createApp'
Object has no method 'createApp'

Time:10-02

I'm new to Javascript. I'm trying to load the following script using Node.js (ver. 0.8.8, it has to be done in this specific version), OS - Windows 10:

//require('look').start();
var main = require('skilap-core');
if (process.argv[2]=="automated") {
    process.on("message",function (msg) {
        if (msg.c == "startapp") {
            var app = main.createApp(msg.data);
            app.startApp(__dirname "/data",function (err) {
                process.send({c:"startapp_repl",data:err})
            });
        }
    })
} else {
    var app = main.createApp();
    app.startApp(__dirname "/data",function (err) {
        if (err) console.log(err);
    });
    module.exports = app;
}

But I get the following error:

> TypeError: Object #<Object> has no method 'createApp'
    at Object.<anonymous> D:\Downloads\skilap\skilap\app.js:13:17)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallback(node.js:244:9)

As I understand, the module loads correctly, but doesn't compile. I've done research in the web and also saw other related questions on this site, but I cannot see what the problem actually is. What does the error mean and what needs to be changed to launch the app? Any help would be appreciated.

CodePudding user response:

You require a module I've never heard of:

var main = require('skilap-core');

This is a javascript object. In your code you are trying to call a createApp() method on that object:

var app = main.createApp();

The main object does not have the createApp() function.

I would use a debugger or insert a console.log(main) after the require to see what the object actually looks like.

I used npm pack skilap-core to download it as a tgz file and examine it. There doesn't appear to be a createApp() function at all. It appears to want to take some kind of custome webapp as a parameter:

module.exports = function (webapp) {
    var app = webapp.web;
    var ctx = webapp._ctx;
    var prefix = webapp.prefix;
    var api = webapp;

    app.get(prefix, function (req, res, next) {
        res.redirect(prefix "/user");
    })

    app.get("/", webapp.layout(), function(req, res, next) {
    ...

CodePudding user response:

I changed the line var main = require('skilap-core') to var main = require('./modules/core/lib/core.js') (the path to the module file) and the module started working.

  • Related