V
V
Vasily Sakovich2017-02-17 18:49:52
Node.js
Vasily Sakovich, 2017-02-17 18:49:52

What's wrong with including node js module?

The first run of the bg.js script goes without problems, but after a reboot an error occurs:
Error: Invocation of form nw.Window.open(string, , function) doesn't match definition nw.Window.open(string url, optional object options, optional function callback) at Object.normalizeArgumentsAndValidate(extensions::schemaUtils:112:11) at Object. (extensions::binding:414:30) at Promise (D:\wasa2\documents\projects\postup\lib\wn_.js:5:19) at Object.exports.winOpen (D:\wasa2\documents\projects\ postup\lib\wn_.js:4:12) at fl.checkPath.catch.then (chrome-extension://icbbpfpgimfaggfemjancddfhmipjkjm/bg.js:22:19)
and if everything is collected in one file it works without problems.
bg.js:

'use strict';

var fs = require('fs'),
    wn = require('D:\\wasa2\\documents\\projects\\postup\\lib\\wn_.js'),
    fl = require('D:\\wasa2\\documents\\projects\\postup\\lib\\fl_.js').fl,
    path_ = nw.App.dataPath + '\\user_',
    set = {
        "title": "PostUP",
        "show": true
    };

fl.checkPath(path_)
    .catch((ans) => {
        console.dir(ans);
        if (ans.code === 'ENOENT') {
            return fl.greatePath(path_);
        } else {
            return Promise.reject(ans);
        }
    })
    .then(() => {
        return wn.winOpen('D:\\wasa2\\documents\\projects\\postup\\html\\index.html', set);
    })
    .then((w) => {
        console.dir(w);
    })
    .catch((ans) => {
        console.dir(ans);
    });

fl_.js :
'use strict';
//проверка наличия папки с настройками
exports.fl = {
    checkPath: (path) => {
        return new Promise((resolve, reject) => {
            fs.stat(path_, (err, data) => {
                if (data) {
                    resolve(data);
                } else {
                    reject(err);
                }
            });
        });
    },
    //создаем папку
    greatePath: (path) => {
        return new Promise((resolve, reject) => {
            fs.mkdir(path_, (data) => {
                if (data) {
                    resolve(data);
                } else {
                    reject(data);
                }
            });
        });
    }
}

wn_.js:
'use strict';

exports.winOpen = (url, setings) => {
    return new Promise((resolve, reject) => {
        nw.Window.open(url, setings, function(w) {
            if (w) resolve(w);
            else reject();
        });
    });
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dark Hole, 2017-02-17
@abyrkov

It's hard to figure out what's wrong with you, but it certainly looks like you're calling wn.winOpen without a set. The reason for this is not clear to me. Try to log.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question