Browserify / Electron / AngularJS Error: fs.existsSync is not a function

Browserify / Electron / AngularJS Error: fs.existsSync is not a function

我使用 Browserify 捆绑我的代码后收到 错误:fs.existsSync 不是函数 代码。

在我尝试使用 require() 之前,我一直收到 错误:未定义要求,因为客户端不支持 require 函数。 Browserify 似乎是一种解决方案。我已经设法解决了 browserify 的 require 错误,但出现了另一个错误 - fs.existsSync 不是函数。

这是我的控制台上显示的错误代码:

Error: fs.existsSync is not a function
[159]</</sqlite.prototype.connect@http://127.0.0.1:8080/services/bundle.js:169566:35
[160]</<@http://127.0.0.1:8080/services/bundle.js:169992:29
invoke@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:4718:19
enforcedReturnValue@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:4557:37
invoke@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:4718:19
createInjector/protoInstanceInjector<@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:4517:37
getService@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:4664:39
injectionArgs@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:4688:58
instantiate@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:4730:18
$controller@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:10369:28
compile/<@http://127.0.0.1:8080/views/assets/js/vendors/angular-ui-router.js:4081:28
bind/<@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:1247:18
invokeLinkFn@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:9934:9
nodeLinkFn@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:9335:11
compositeLinkFn@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:8620:13
publicLinkFn@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:8500:30
lazyCompilation@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:8844:25
updateView@http://127.0.0.1:8080/views/assets/js/vendors/angular-ui-router.js:4021:23
compile/</<@http://127.0.0.1:8080/views/assets/js/vendors/angular-ui-router.js:3959:11
$broadcast@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:18005:28
transitionTo/$state.transition<@http://127.0.0.1:8080/views/assets/js/vendors/angular-ui-router.js:3352:22
processQueue@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:16383:28
scheduleProcessQueue/<@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:16399:27
$eval@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:17682:28
$digest@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:17495:31
$apply@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:17790:24
done@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:11831:47
completeRequest@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:12033:7
requestLoaded@http://127.0.0.1:8080/views/assets/js/vendors/angular.js:11966:9
 <div ui-view="" class="ng-scope">

我正在使用 electron、angularjs 和 sqlite 来构建我的应用程序,但我遇到了这个错误,我们将不胜感激。

通过在 main.js 文件(电子输入文件)中启用 nodeIntegration: true,我设法在没有 browserify 的情况下解决了我的错误。然后我能够毫无问题地将我的脚本 (coolscript.js) 加载到我的 html 中,其中包含 require 函数 -

<script>
   require('coolscript.js')
</script>