我在做一个电子项目。通过this tutorial的命令,我在package.json
文件中添加了这个脚本:"electron-dev": "electron ."
当我尝试使用该脚本运行应用程序时,该应用程序除了在App.css
文件中指定的颜色#282c34之外什么都没有,并且控制台打印了这个错误:
(node:13384) electron: Failed to load URL: http://localhost:3000/ with error: ERR_CONNECTION_REFUSED
(Use `electron --trace-warnings ...` to show where the warning was created)
在我使用electron --trace-warnings ...
之后,我得到了这样的结果:
electron : The term 'electron' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ electron --trace-warnings ...
+ ~~~~~~~~
+ CategoryInfo : ObjectNotFound: (electron:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
有人知道怎么帮忙吗?
发布于 2021-07-07 01:10:26
而不是从命令行运行命令(在您的情况下似乎是PowerShell),您必须在package.json
中创建一个新脚本,如下所示:
{
// ...
"scripts": {
"electron-dev": "electron .",
"electron-trace": "electron --trace-warnings ."
},
// ...
}
文件的其余部分应该保持不变。所示命令中的...
想要向您展示的是,您必须使用所有其他选项来完成命令。由于您只指定.
作为应用程序的路径,这就是所需的全部内容。
获得CommandNotFoundException
的原因是,Electron只安装在NPM环境中,只有NPM才能启动它。也就是说,当您像我上面显示的那样添加脚本时,您可以通过执行以下命令来运行它:
npm run electron-trace
调试愉快!
https://stackoverflow.com/questions/68270523
复制相似问题