在处理特定项目时,我发现可以使用pkg模块编译控制台应用程序。安装后,我在主应用程序上对其进行了测试,并且可以正常工作。当我在“ Service.js”(项目中的服务安装程序)上尝试时,收到警告(尽管我在node_modules文件夹中有节点窗口)
Warning Cannot find module 'node-windows' from 'C:\Users\Uchenna\Documents\NodeJS\Ghost'
C:\ Users \ Uchenna \ Documents \ NodeJS \ Ghost \ Service.js
我尝试忽略它,然后继续运行“ Service.exe --install”,然后出现此错误:
Error: Cannot find module 'node-windows'
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:592:15)
at Function.Module._resolveFilename (pkg/prelude/bootstrap.js:1280:46)
at Function.Module._load (internal/modules/cjs/loader.js:518:25)
at Module.require (internal/modules/cjs/loader.js:648:17)
at Module.require (pkg/prelude/bootstrap.js:1159:31)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (C:\snapshot\Ghost\Service.js:0:0)
at Module._compile (pkg/prelude/bootstrap.js:1254:22)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:711:10)
at Module.load (internal/modules/cjs/loader.js:610:32)
这是Service.js文件中的代码
const Service = require("node-windows").Service;
class ServiceInstaller
{
constructor () {
var logServerService = new Service({
name: "Log Server Service",
description: "Listens for data to log",
script: "./DataLoggerServer.exe"
});
var mainService = new Service({
name: "Main Application Service",
description: "Logs data (or errors) to the Log Server Service",
script: "./Ghost.exe"
});
}
installServices () {
logServerService.install();
mainService.install();
logServerService.on("install", function () {
logServerService.start();
console.log("Successfully installed the 'Log Server' service\n");
});
mainService.on("install", function () {
mainService.start();
console.log("Successfully installed the main service\n");
});
}
uninstallServices () {
logServerService.uninstall();
mainService.uninstall();
logServerService.on("install", function () {
logServerService.start();
console.log("Successfully uninstalled the 'Log Server' service\n");
});
mainService.on("install", function () {
mainService.start();
console.log("Successfully uninstalled the main service\n");
});
}
}
var installer = new ServiceInstaller();
if (process.argv[2] == "install") {
installer.installServices();
}
else if (process.argv[2] == "uninstall") {
installer.uninstallServices();
}
else {
console.log("Not running...\n");
}
答案 0 :(得分:1)
使用pkg进行构建时,某些软件包显示此错误。
对我来说是bcrypt。
查看错误消息并找出错误消息引用的可执行文件。然后从node_modules文件夹复制该可执行文件(大多数情况下将从该文件夹复制),并将其粘贴到可执行文件旁边。
这为我解决了这个问题