Skip to content

Commit e88d159

Browse files
authored
fix: child_process commands throw when pkg app try to call itself (#90)
1 parent 7c24763 commit e88d159

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,23 @@ await exec(['app.js', '--target', 'host', '--output', 'app.exe']);
402402

403403
## Troubleshooting
404404

405+
### Error: Cannot find module XXX (when using `child_process`)
406+
407+
When using `child_process` methods to run a new process pkg by default will invoke it using NodeJS runtime that is built into the executable. This means that if you are trying to spawn the packaged app itself you will get above error. In order to avoid this you must set `PKG_EXECPATH` env set to `""`:
408+
409+
```js
410+
const { spawn } = require('child_process');
411+
412+
const child = spawn(process.execPath, [process.argv[1]], {
413+
env: {
414+
...process.env,
415+
PKG_EXECPATH: '',
416+
},
417+
});
418+
```
419+
420+
More info [here](https://github.com/yao-pkg/pkg/pull/90)
421+
405422
### Error: ENOENT: no such file or directory, uv_chdir
406423

407424
This error can be caused by deleting the directory the application is

prelude/bootstrap.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,8 @@ function payloadFileSync(pointer) {
20062006
}
20072007
const opts = args[pos];
20082008
if (!opts.env) opts.env = _extend({}, process.env);
2009-
if (opts.env.PKG_EXECPATH === 'PKG_INVOKE_NODEJS') return;
2009+
// see https://github.com/vercel/pkg/issues/897#issuecomment-1049370335
2010+
if (opts.env.PKG_EXECPATH !== undefined) return;
20102011
opts.env.PKG_EXECPATH = EXECPATH;
20112012
}
20122013

0 commit comments

Comments
 (0)