【问题标题】:TypeError: fs.existsSync is not a function (Electron/ReactJS/Typescript)TypeError:fs.​​existsSync 不是函数(Electron/ReactJS/Typescript)
【发布时间】:2020-02-26 05:31:42
【问题描述】:

我正在使用 Electron 和 ReactJS 和 typescript 构建跨平台桌面应用程序。所以有一个像下面这样的功能。该功能正在调用按钮单击,它应该在连接的默认打印机中打印文本。这是处理打印操作的第三方库。但问题是当我使用此功能时,我的应用程序无法加载。它崩溃了。

function printcheck() {
        const printer = require('electron-print');

        app.on('ready', function() {
            printer.print("Text sent to printer.");
        });
    }

显示的错误是 TypeError: fs.existsSync is not a function 并且错误指向 node_modules/electron/index.js:7。我也使用过许多其他第三方打印库。此时所有人都崩溃了。

function getElectronPath () {
>  7 |   if (fs.existsSync(pathFile)) {

任何帮助将不胜感激。

【问题讨论】:

  • 提供您使用的 Electron 版本以及崩溃的最小示例(例如使用electronjs.org/fiddle)将有助于调试错误。

标签: reactjs typescript electron


【解决方案1】:

您需要在后端(即 Node.js)上进行打印。在前端代码中是做不到的。

【讨论】:

    猜你喜欢
    • 2020-02-12
    • 2021-09-24
    • 2021-10-06
    • 2020-11-16
    • 2020-04-26
    • 2020-03-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-26
    相关资源
    最近更新 更多