V
V
Vasily Sakovich2017-02-17 00:08:50
Node.js
Vasily Sakovich, 2017-02-17 00:08:50

What causes an error when exporting a node.js module?

After reloading, the bg.js script prints an error to the console:
Uncaught Error: Cannot find module './lib/wn_.js'
at Function.Module._resolveFilename (module.js:494:15)
at Function.Module._load (module. js:437:25)
at Module.require (module.js:522:17)
at require (internal/module.js:20:19)
at self.require (:11:26)
at self.require (:11: 26)
at chrome-extension://icbbpfpgimfaggfemjancddfhmipjkjm/bg.js:5:10

the first time you run the script everything is ok.
bg.js:

var fs = require('fs'),
    wn = require('./lib/wn_.js').wn,
    fl = require('./lib/fl_.js').fl,
    path_ = nw.App.dataPath + '\\user_'; 

Promise.resolve(fl.checkPath(path_))
    .catch((ans) => {
        if (ans.code === 'ENOENT') {
            return Promise.resolve(fl.greatePath(path_));
        } else {
            return Promise.reject(ans);
        }
    })
    .then(() => {
        return Promise.resolve(
            wn.winOpen('./html/index.html', {
                id: "1",
                title: "PostUP",
                show: true
            })
        );
    })
    .then((w) => {
        console.dir(w);
    })
    .catch((ans) => {
        console.dir(ans);
    });

fl_.js
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) {
                    reject(err);
                } else {
                    resolve();
                }
            });
        });
    }
};

wn_.js:
exports.wn = {
    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)
N
Nwton, 2017-02-17
@wasa20081980

Uncaught Error: Cannot find module './lib/wn_.js'

The compiler cannot get the wn_js file. What else can be said. Try to write an absolute path / remove lib / add an external folder / in general, play with the path. The error is somewhere here:require('./lib/wn_.js')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question