microsoft / node-pty

Fork pseudoterminals in Node.JS
Other
1.46k stars 235 forks source link

Error when package exe file in Windows 10. #503

Closed Kenhuey closed 2 years ago

Kenhuey commented 2 years ago

Environment details

Issue description

When I using pkg to package executable win64 exe file, something go wrong. I separate all the functions to test, only node-pty gose wrong in runtime. Use "node ./dist/main.js" works well, but issue is run at after build exe file. (Not in Electron,)

Related code:

import { IPty, spawn as ptySpawn } from "node-pty";
...
const TARGET_EXE_PATH: string = ...; /* Full path, eg: "D:/foo/bar.exe". */
const targetProcess: IPty = ptySpawn(TARGET_EXE_PATH, [], {
    cwd: process.cwd(),
});

Error logs:

[2021-10-21 17:09:50] [ERROR] <10_0_12_11 11120> console - innerError Error: Cannot find module '../build/Debug/pty.node'
Require stack:
- C:\snapshot\myproject1\node_modules\node-pty\lib\windowsPtyAgent.js
- C:\snapshot\myproject1\node_modules\node-pty\lib\windowsTerminal.js
- C:\snapshot\myproject1\node_modules\node-pty\lib\index.js
- C:\snapshot\myproject1\dist\main.js
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
    at Function._resolveFilename (pkg/prelude/bootstrap.js:1819:46)
    at Function.Module._load (internal/modules/cjs/loader.js:745:27)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at Module.require (pkg/prelude/bootstrap.js:1719:31)
    at require (internal/modules/cjs/helpers.js:92:18)
    at new WindowsPtyAgent (C:\snapshot\myproject1\node_modules\node-pty\lib\windowsPtyAgent.js:57:40)
    at new WindowsTerminal (C:\snapshot\myproject1\node_modules\node-pty\lib\windowsTerminal.js:50:24)
    at spawn (C:\snapshot\myproject1\node_modules\node-pty\lib\index.js:28:12)
    at C:\snapshot\myproject1\dist\main.js:64:58 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\snapshot\\myproject1\\node_modules\\node-pty\\lib\\windowsPtyAgent.js',
    'C:\\snapshot\\myproject1\\node_modules\\node-pty\\lib\\windowsTerminal.js',
    'C:\\snapshot\\myproject1\\node_modules\\node-pty\\lib\\index.js',
    'C:\\snapshot\\myproject1\\dist\\main.js'
  ],
  pkg: true
}
[2021-10-21 17:09:50] [ERROR] <10_0_12_11 11120> console - (node:11120) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '1' of null
    at process.dlopen (pkg/prelude/bootstrap.js:2071:69)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1131:18)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at Module.require (pkg/prelude/bootstrap.js:1719:31)
    at require (internal/modules/cjs/helpers.js:92:18)
    at new WindowsPtyAgent (C:\snapshot\myproject1\node_modules\node-pty\lib\windowsPtyAgent.js:53:36)
    at new WindowsTerminal (C:\snapshot\myproject1\node_modules\node-pty\lib\windowsTerminal.js:50:24)
    at spawn (C:\snapshot\myproject1\node_modules\node-pty\lib\index.js:28:12)
(Use `myproject1 --trace-warnings ...` to show where the warning was created)
[2021-10-21 17:09:50] [ERROR] <10_0_12_11 11120> console - (node:11120) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
[2021-10-21 17:09:50] [ERROR] <10_0_12_11 11120> console - (node:11120) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Kenhuey commented 2 years ago

Seems like i found the part of solution of that. Copy ./node_module/node-pty/build/release/pty.node to the exe root path.

But I still meet a problem on pkg :(

Error logs:

[2021-10-21 19:35:39] [ERROR] <10_0_12_11 11656> console - innerError TypeError: Cannot read property '1' of null
    at process.dlopen (pkg/prelude/bootstrap.js:2071:69)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1131:18)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at Module.require (pkg/prelude/bootstrap.js:1719:31)
    at require (internal/modules/cjs/helpers.js:92:18)
    at new WindowsPtyAgent (C:\snapshot\myproject1\node_modules\node-pty\lib\windowsPtyAgent.js:57:40)
    at new WindowsTerminal (C:\snapshot\myproject1\node_modules\node-pty\lib\windowsTerminal.js:50:24)
    at spawn (C:\snapshot\myproject1\node_modules\node-pty\lib\index.js:28:12)
Tyriar commented 2 years ago

This error seems specific to pkg, we can't answer it unfortunately.