![](/img/trans.png)
[英]How to fix "cannot find module'./node'' while compiling with pkg
[英]NodeJS: How to fix "cannot find module 'node-windows' while compiling with pkg
在处理特定项目时,我发现我可以使用 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");
}
使用 pkg 构建时的某些软件包显示此错误。
对我来说是 bcrypt。
查看错误消息并找出错误消息所指的可执行文件。 然后从 node_modules 文件夹中复制该可执行文件(主要来自该文件夹),并将其粘贴到可执行文件旁边。
这为我解决了这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.