-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
not work with node pkg build #54
Comments
Did you remember to call run? I haven't used // path_ is to make sure pkg's regex detects path.join(__dirname) properly (https://github.com/vercel/pkg#detecting-assets-in-source-code)
import path_ from 'path';
// try to ensure pkg includes os-service -- make sure relative path is correct
const path = path_;
path.join(__dirname, './node_modules/os-service');
let service = undefined;
async function lazyLoadService() {
if (service) {
return service;
}
const cwd = process.cwd();
if (isPkg) {
// include os-service only after running in the correct folder, to resolve service.node properly (though os-service expects it as ./build/Release/service
process.chdir(path.dirname(process.execPath));
}
try {
service = await import('os-service');
} finally {
if (isPkg) {
process.chdir(cwd);
}
}
return service;
}
/**
* run a service
* CALL THIS WHEN YOU FIRST START YOUR PROGRAM AS A SERVICE OTHERWISE WINDOWS WILL COMPLAIN
* ...it's probably safe to call even if not running as a service
*/
export async function run(onStop = () => { }) {
// throw if service.node couldn't be loaded
await lazyLoadService();
service.run(async () => {
let returnCode = 0;
try {
if (typeof onStop === 'function') {
await onStop();
}
} catch (err: any) {
returnCode = parseInt(err.code, 10) || 1;
throw err;
} finally {
service.stop(returnCode);
}
});
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
service created with node-os-service for script successfully install and run.
but while I pack my project with vercel/pkg, It installs the service but while starting the service it gives the bellow error. What am I doing wrong?
Thanks in advance.
The text was updated successfully, but these errors were encountered: