本文介绍了electron,browserify之后,fs.existsSync不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
我阅读了很多关于 browserify 和 electron 以及 gui 浏览器问题的信息但是browserify还是有问题,说fs.existsSync不是函数",required没有定义"
* 全文*我用电子创建了简单的 gui,有 package.json 文件、main.js 和 index.html 文件 + 3,4 个 html 文件,我想在其中创建与 require 一起使用的简单加载显示保存窗口"
该功能在 index.html 文件中有效,但在 load.html 文件中无法正常工作,因此我使用命令浏览 main.js
var fs = require('electron')//console.log(require('fs').existsSync);var remote = require('electron').remote;//var remote = require('remote');var dialog = require('electron').remote 进入 main.bundle3.js,使用,(在 cmd 中)
浏览 main.js >main.bundle3.js然后 load.html 文件大喊 require 没有定义和
<代码>>main.bundle3.js:6945 Uncaught TypeError: fs.existsSync 不是函数在对象.<匿名>(main.bundle3.js:6945)在 Object.require.36.fs (main.bundle3.js:6951)在 s (main.bundle3.js:1)在 main.bundle3.js:1在对象.<匿名>(main.bundle3.js:6794)在 Object.require.35._process (main.bundle3.js:6937)在 s (main.bundle3.js:1)在 e (main.bundle3.js:1)在 main.bundle3.js:1(匿名)@ main.bundle3.js:6945要求.36.fs @ main.bundle3.js:6951s@main.bundle3.js:1(匿名)@ main.bundle3.js:1(匿名)@ main.bundle3.js:6794要求.35._process @ main.bundle3.js:6937s@main.bundle3.js:1e@main.bundle3.js:1(匿名)@ main.bundle3.js:1
package.json
{名称":RDF",版本":0.1.0","main": "main.js",脚本":{测试":摩卡 -u 出口 -R 规格测试/索引"},开发依赖":{电子":^1.6.2",电子包装器":^8.6.0","html-browserify": "0.0.6",jquery":^3.2.1"}}和 load.html 文件
<!DOCTYPE html><html><头><meta charset="UTF-8"><script src="https://cdn.plot.ly/plotly-latest.min.js"></script><!--<script src="main.js"></script>--><script src="main.bundle3.js"></script><!-- <script type="text/javascript" src="main.js"></script>--><script type="text/javascript" src="./lib/jquery-1.7.2.min.js"></script></头><身体><h3>加载</h3><p>加载数据</p><!--<input type="button" value="Details" onclick="javascript:$('#mainContainer').load('index.html');"/><br><div id="mainContainer"></div>--><div id="tab33"><div style="text-align:center;"><input type="text" placeholder="只选择一个文件" id="actual-file" disabled="disabled"/><input type="button" value="选择一个文件" id="select-file"/></div><br><br><textarea id="content-editor" rows="5"></textarea><br><br><input type="button" id="save-changes" value="保存更改"/><input type="button" id="delete-file" value="删除文件"/></div><小时><div style="text-align:center;"><p>他的文件内容将与编辑器相同.</p><input type="button" value="选择一个文件" id="create-new-file"/></div><脚本>var fs = 要求('fs')var {remote} = require('electron').remote ;var {dialog} = require('electron').remotedocument.getElementById('select-file').addEventListener('click',function(){dialog.showOpenDialog(函数(文件名){如果(文件名 === 未定义){console.log("没有选择文件");}别的{document.getElementById('actual-file').value = fileNames[0];readFile(fileNames[0], fileReadComplete);}});},错误的);//document.getElementById('save-changes').addEventListener('click',function(){var actualFilePath = document.getElementById("actual-file").value;如果(实际文件路径){saveChanges(actualFilePath,document.getElementById('content-editor').value);}别的{alert("先选择一个文件");}},错误的);//document.getElementById('delete-file').addEventListener('click',function(){var actualFilePath = document.getElementById("actual-file").value;如果(实际文件路径){删除文件(实际文件路径);document.getElementById("实际文件").value = "";document.getElementById("content-editor").value = "";}别的{alert("先选择一个文件");}},错误的);document.getElementById('create-new-file').addEventListener('click',function(){var content = document.getElementById("content-editor").value;dialog.showSaveDialog(函数(文件名){如果(文件名 === 未定义){console.log("你没有保存文件");返回;}fs.writeFile(文件名,内容,功能(错误){如果(错误){alert("创建文件出错"+ err.message)}alert("文件保存成功");});});},错误的);函数文件读取完成(数据){我的数据 = 数据;//做你想做的}函数读取文件(文件路径,回调){fs.readFile(filepath, 'utf-8', function (err, data) {如果(错误){alert("读取文件出错:" + err.message);返回;}回调(数据);document.getElementById("content-editor").value = data;});}函数删除文件(文件路径){fs.exists(文件路径,函数(存在){如果(存在){//文件存在删除fs.unlink(文件路径,函数(错误){如果(错误){alert("更新文件出错"+ err.message);控制台日志(错误);返回;}});} 别的 {alert("此文件不存在,无法删除");}});}函数 saveChanges(文件路径,内容){fs.writeFile(文件路径,内容,功能(错误){如果(错误){alert("更新文件出错"+ err.message);控制台日志(错误);返回;}alert("文件保存成功");});}</脚本></div><!-- <script data-main="main" src="require.js"></script>--></身体></html>完整的 main.js 文件
//console.log(require('fs'));console.log(require('module').globalPaths);常量 {电子} = 要求('电子');常量 {浏览器窗口} = 要求('电子')常量 {应用程序} = 要求('电子');//@show(应用程序)常量路径 = 要求('路径')//console.log(process.env.PATH);//(D:electron-v1.6.1-win32-x64
esourcesdefault_app.asrmain.js:325:5)//const BrowserWindow = require('browser-window')常量 url = 要求('url')var html = require('html-browserify');var fs = require('电子')//console.log(require('fs').existsSync);var remote = require('electron').remote;//var remote = require('remote');var dialog = require('electron').remote//dialog = require('electron').dialog//对话 =remote.require('对话')//var load_=require('./load_.js')//浏览 htmlvar through = require('through');var htmlclean = 需要('htmlclean');module.exports = 函数(文件,选项){选项 = 选项 ||{};options.htmlclean =typeof options.htmlclean !== '未定义'?options.htmlclean:真;变量缓冲区 = '';if (!/.(tpl|html)/.test(file)) {通过()返回;} 别的 {返回通过(函数(块){返回缓冲区 += chunk.toString();}, 功能() {var jst = buffer.toString();如果(options.htmlclean){//options.htmlclean 是真的if (typeof options.htmlclean === 'object') {//options.htmlclean 是 htmlclean 模块的选项对象jst = htmlclean(jst, options.htmlclean);} 别的 {//否则,使用默认选项清理jst = htmlclean(jst);}}var 编译 = 'module.exports = ';编译 += JSON.stringify(jst);编译 += ';
';this.queue(编译);返回 this.queue(null);});}}//requirejs.config({//默认从js/lib加载任何模块ID//baseUrl: 'js/lib',//除了,如果模块ID以app"开头,//从 js/app 目录加载它.路径//config 是相对于 baseUrl 的,并且//从不包含.js"扩展名,因为//路径配置可以是一个目录.//路径:{// 应用程序: ' '/
The End
相关推荐
具体实现代码如下: laydate.render({ elem: '#start_time', min:0, //,type: 'date' //默认,可不填}); 只要加一个min参数,就可以控制了。0表示之前的日期不可...
2024-11-29
前端开发问题
133
在JavaScript中,我们有多种方法可以删除数组中的指定元素。以下给出了5种常见的方法并提供了相应的代码示例: 1.使用splice()方法: let array = [0, 1, 2, 3, 4, 5];let index = array.indexOf(2);if (index -1) { array.splice(index, 1);}// array = [0,...
2024-11-22
前端开发问题
182
主页面上显示了一个合计,在删除和增加的时候需要更改这个总套数的值: //html代码div class="layui-inline layui-show-xs-block" style="margin-left: 10px" id="sumDiv"spanSOP合计:/spanspan${totalNum}/spanspan套/span/div 于是在我们删除这个条数据后,...
2024-11-14
前端开发问题
156
在Layui中,如果你想设置日期时间选择器(datetime)的默认结束时间为当天的23:59:59,你可以使用如下代码: laydate.render({ elem: '#test10' ,type: 'datetime' ,range: true ,max: '{:date("Y-m-d 23:59:59")}' ,ready: function(date){ $(".layui-laydat...
2024-10-24
前端开发问题
279
问题描述 我想改变layui时间日历布局大小,这个要怎么操作呢? 解决办法 可以用css样式对时间日历进行重新布局,具体代码如下: !DOCTYPE htmlhtmlheadmeta charset="UTF-8"title/titlelink rel="stylesheet" href="../../layui/css/layui.css" /style#test-...
2024-10-24
前端开发问题
271
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...
2024-10-18
前端开发问题
301






大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)