【发布时间】:2018-04-12 21:51:13
【问题描述】:
我正在尝试构建一个 Electron 应用程序,该应用程序可以快速将机器信息提供给用户。我正在尝试使用 npm 模块“shelljs”来在节点环境中使用 shell 脚本。但是 Electron 并不真正支持 shelljs,所以我有点担心。有一种解决方法,包括使用节点二进制文件的绝对路径。不知道他们是什么意思,所以我想你们可以帮忙。
我得到的解决方法取自here,他们这样说:
像任何常规变量一样设置它。
// This is inside your javascript file
var shell = require('shelljs');
shell.config.execPath = 'path/to/node/binary'; // Replace this with the real path
// The rest of your script...
这是我在execPath 上得到未定义的代码:
const shell = require('shelljs')
const path = require('path')
shell.confic.execPath = path.join('C:', 'Program Files', 'nodejs', 'node_modules', 'npm', 'bin')
我是否以错误的方式解释了解决方法?
【问题讨论】:
-
我可能错了,但您的应用程序的
node_modules文件夹中有.bin文件夹吗?package.json中存储为 deps 的项目的二进制文件通常放在那里。这似乎也是shell.confic.execPath中的错字 -
您可以使用
process.execPath获得电子路径,因此很可能是shell.config.execPath = process.execPath。您可以通过设置环境变量ELECTRON_RUN_AS_NODE=1来运行电子有节点,所以在您的情况下process.env.ELECTRON_RUN_AS_NODE=1
标签: javascript node.js electron shelljs