Answer the question
In order to leave comments, you need to log in
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);
});
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();
}
});
});
}
};
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
Uncaught Error: Cannot find module './lib/wn_.js'
require('./lib/wn_.js')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question