Skip to content

Commit

Permalink
fix: child_process commands throw when pkg app try to call itself (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando authored Sep 17, 2024
1 parent 7c24763 commit e88d159
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,23 @@ await exec(['app.js', '--target', 'host', '--output', 'app.exe']);

## Troubleshooting

### Error: Cannot find module XXX (when using `child_process`)

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 `""`:

```js
const { spawn } = require('child_process');

const child = spawn(process.execPath, [process.argv[1]], {
env: {
...process.env,
PKG_EXECPATH: '',
},
});
```

More info [here](https://github.com/yao-pkg/pkg/pull/90)

### Error: ENOENT: no such file or directory, uv_chdir

This error can be caused by deleting the directory the application is
Expand Down
3 changes: 2 additions & 1 deletion prelude/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,8 @@ function payloadFileSync(pointer) {
}
const opts = args[pos];
if (!opts.env) opts.env = _extend({}, process.env);
if (opts.env.PKG_EXECPATH === 'PKG_INVOKE_NODEJS') return;
// see https://github.com/vercel/pkg/issues/897#issuecomment-1049370335
if (opts.env.PKG_EXECPATH !== undefined) return;
opts.env.PKG_EXECPATH = EXECPATH;
}

Expand Down

0 comments on commit e88d159

Please sign in to comment.