Browserify / Electron / AngularJS 错误:fs.existsSync 不是函数
Posted
技术标签:
【中文标题】Browserify / Electron / AngularJS 错误:fs.existsSync 不是函数【英文标题】:Browserify / Electron / AngularJS Error: fs.existsSync is not a function 【发布时间】:2019-12-27 19:05:31 【问题描述】:在我使用 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 来构建我的应用程序,但我遇到了这个错误,我们将不胜感激。
【问题讨论】:
【参考方案1】:通过在 main.js 文件(电子入口文件)中启用 nodeIntegration: true
,我已经设法在没有 browserify 的情况下解决了我的错误。然后我就可以毫无问题地将我的脚本(coolscript.js)加载到我的html中,它里面有require函数 -
<script>
require('coolscript.js')
</script>
【讨论】:
以上是关于Browserify / Electron / AngularJS 错误:fs.existsSync 不是函数的主要内容,如果未能解决你的问题,请参考以下文章