Skip to content

fix: child_process commands throw when pkg app try to call itself #90

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

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading