Reputation: 1672
Working on deploying an app with PKG for Windows as a service via Node-Windows.
I have my NodeWindows install and uninstall scripts, and I'm trying to use PKG to make those into Windows executables. PKG creates the .exe
files, but when I run the file, it throws an error like the one below:
pkg/prelude/bootstrap.js:1226 return wrapper.apply(this.exports, args); ^
ReferenceError: svc is not defined
at Object.<anonymous> (C:\snapshot\transient\installTransient2.js:0)
at Module._compile (pkg/prelude/bootstrap.js:1226:22)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (pkg/prelude/bootstrap.js:1281:12)
at run (bootstrap_node.js:432:7)
at startup (bootstrap_node.js:192:9)
at bootstrap_node.js:547:3
with my Node-windows script like this:
var Service = require('node-windows').Service;
var scv = new Service({
name: 'Transient2',
description: 'Yet Another File Transfer Utility in NodeJS',
script: 'server.js'
});
svc.on('install', () => {
console.log('successfully installed');
svc.start();
});
svc.install();
I want to think that node-windows isn't getting packed into the Executable. According to PKG's documentation, it should "shim" in anything in a require statement, unless it's declared with a path.join()
call.
How can I package my app in an installer that creates a service in windows?
Upvotes: 1
Views: 1429
Reputation: 98
The hint is in the error - you have declared the variable name 'scv' instead of 'svc' on line 3 in your Node.js script.
This means that when you add the 'install' event handler on line 9 to 'svc' it cannot find that variable because it was misspelt. This is why you're receiving the ReferenceError described.
Upvotes: 3