【问题标题】:Uncaught TypeError: r.existsSync is not a function in Angular 6 and Electron desktop application未捕获的 TypeError:r.existsSync 不是 Angular 6 和 Electron 桌面应用程序中的函数
【发布时间】:2018-11-30 10:10:48
【问题描述】:

我正在将桌面应用程序从 Angular 5 和 Electron 2 框架升级到 Angular 6,但在运行/构建应用程序时出现此错误:npm start 运行 electron .

错误:

Uncaught TypeError: r.existsSync is not a function
at Object.<anonymous> (main.4ff68b38699fd48ecfa7.js:1)
at Object.vbkW (main.4ff68b38699fd48ecfa7.js:1)
at p (runtime.a66f828dca56eeb90e02.js:1)
at Object.zUnb (main.4ff68b38699fd48ecfa7.js:1)
at p (runtime.a66f828dca56eeb90e02.js:1)
at Object.7 (main.4ff68b38699fd48ecfa7.js:1)
at p (runtime.a66f828dca56eeb90e02.js:1)
at n (runtime.a66f828dca56eeb90e02.js:1)
at Array.e [as push] (runtime.a66f828dca56eeb90e02.js:1)
at main.4ff68b38699fd48ecfa7.js:1

我认为这只是 Angular 6 的问题。我无法从这个错误堆栈跟踪中了解很多。该应用程序在 Angular 5 中运行良好。 非常感谢任何帮助。

【问题讨论】:

    标签: angular electron angular5 upgrade angular6


    【解决方案1】:

    打包的捆绑包必须破坏某些东西。 This issue 看起来非常相似。

    您可以尝试按照那里的建议将require('fs') 替换为window.require('fs')

    【讨论】:

    • 感谢您的建议。我试过这个,但现在它抛出错误:main.ts(5,25): error TS2339: Property 'require' does not exist on type 'Window'.。我可能做得不对。
    • @atik,我相信您不再需要它,但对于任何感兴趣的人:似乎需要在BrowserWindow 选项中将nodeIntegration 设置为true,如下所述:github.com/electron/electron/issues/7300#issuecomment-493077796 .
    【解决方案2】:

    您是否使用require 导入了模块。

    var r= require('fs');
    

    【讨论】:

    • 如果您根本没有导入,您不会收到 "Cannot read property 'existsSync' of undefined" 错误吗?我认为错误来自其他地方。
    猜你喜欢
    • 2018-01-17
    • 2018-03-11
    • 2019-11-03
    • 2021-06-17
    • 2020-10-26
    • 1970-01-01
    • 1970-01-01
    • 2018-04-23
    • 1970-01-01
    相关资源
    最近更新 更多