我试图在ElectronJS应用程序中使用node-pty,但我很难让它工作。
我使用Electron React Boilerplate作为我的项目的基础。
问题重现:
git clone --depth 1 --branch main https://github.com/electron-react-boilerplate/electron-react-boilerplate.git test-electron-nodepty
cd test-electron-nodepty
npm i
cd release/app
npm i --save node-pty
cd ../..
npm i
字符串
(note:我在release/app
中安装了node-pty
,按照instructions here在Electron React Boilerplate中安装本机依赖项)
然后我更新src/main/main.ts
如下:
import pty from 'node-pty';
pty.spawn('bash', [], {
name: 'xterm-color',
cols: 80,
rows: 30,
cwd: process.env.HOME,
env: process.env,
});
型
运行npm run start
,得到错误:
TypeError: Cannot read properties of undefined (reading 'spawn')
at Object.<anonymous> (/Users/dcentore/Downloads/test-electron-nodepty/src/main/main.ts:35:5)
at Module._compile (node:internal/modules/cjs/loader:1271:14)
at Module.m._compile (/Users/dcentore/Downloads/test-electron-nodepty/node_modules/ts-node/src/index.ts:1618:23)
at node:internal/modules/cjs/loader:1326:10
at Object.require.extensions.<computed> [as .ts] (/Users/dcentore/Downloads/test-electron-nodepty/node_modules/ts-node/src/index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1126:32)
at node:internal/modules/cjs/loader:967:12
at Function.<anonymous> (node:electron/js2c/asar_bundle:2:13377)
at Function.Module._load (/Users/dcentore/Downloads/test-electron-nodepty/node_modules/runtime-required/runtime-required.js:34:23)
at loadApplicationPackage (/Users/dcentore/Downloads/test-electron-nodepty/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js:121:16)
型
我也试过:
npm run build
node release/app/dist/main/main.js
型
我得到这个错误:
innerError Error: Cannot find module '../build/Debug/pty.node'
Require stack:
- /Users/dcentore/Downloads/test-electron-nodepty/release/app/node_modules/node-pty/lib/unixTerminal.js
- /Users/dcentore/Downloads/test-electron-nodepty/release/app/node_modules/node-pty/lib/index.js
- /Users/dcentore/Downloads/test-electron-nodepty/release/app/dist/main/main.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
at Module._load (node:internal/modules/cjs/loader:901:27)
at Module.require (node:internal/modules/cjs/loader:1115:19)
at require (node:internal/modules/helpers:130:18)
at Object.<anonymous> (/Users/dcentore/Downloads/test-electron-nodepty/release/app/node_modules/node-pty/lib/unixTerminal.js:34:15)
at Module._compile (node:internal/modules/cjs/loader:1241:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Module._load (node:internal/modules/cjs/loader:938:12)
at Module.require (node:internal/modules/cjs/loader:1115:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/dcentore/Downloads/test-electron-nodepty/release/app/node_modules/node-pty/lib/unixTerminal.js',
'/Users/dcentore/Downloads/test-electron-nodepty/release/app/node_modules/node-pty/lib/index.js',
'/Users/dcentore/Downloads/test-electron-nodepty/release/app/dist/main/main.js'
]
}
/Users/dcentore/Downloads/test-electron-nodepty/release/app/node_modules/node-pty/lib/unixTerminal.js:40
throw outerError;
^
Error: The module '/Users/dcentore/Downloads/test-electron-nodepty/release/app/node_modules/node-pty/build/Release/pty.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 116. This version of Node.js requires
NODE_MODULE_VERSION 115. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
at Module._extensions..node (node:internal/modules/cjs/loader:1327:18)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Module._load (node:internal/modules/cjs/loader:938:12)
at Module.require (node:internal/modules/cjs/loader:1115:19)
at require (node:internal/modules/helpers:130:18)
at Object.<anonymous> (/Users/dcentore/Downloads/test-electron-nodepty/release/app/node_modules/node-pty/lib/unixTerminal.js:29:11)
at Module._compile (node:internal/modules/cjs/loader:1241:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Module._load (node:internal/modules/cjs/loader:938:12) {
code: 'ERR_DLOPEN_FAILED'
}
型
我已经花了相当多的时间尝试解决方案,从改变软件包版本到使用电子构建器,但我似乎不能找出正确的魔法酱料,使一切一起工作。
我用的是ARM Mac。
1条答案
按热度按时间d6kp6zgx1#
根据
node-pyt
的示例用法,导入应该写为:字符串