javascript - Node.js错误: "Unexpected token ;" while on node-webkit

标签 javascript node.js node-webkit

我试图关注 this在 node-webkit 上制作简单文本编辑器的教程,但是当我到达连接模块的部分时,我收到此错误:

Uncaught node.js Error 

SyntaxError: Unexpected token ;
    at exports.runInThisContext (vm.js:69:16)
    at Module._compile (module.js:435:25)
    at Object.Module._extensions..js (module.js:470:10)
    at Module.load (module.js:352:32)
    at Function.Module._load (module.js:308:12)
    at Module.require (module.js:360:17)
    at require (module.js:376:17)
    at window.require (eval at undefined, <anonymous>:1:112)
    at eval (file:///Users/Gonzo/Documents/node-webkit-v0.9.2-osx-ia32/js/main.js:1:12)

这是 main.js 代码,似乎有错误:

var file = require('file.js');

console.log(file.open, file.save);

编辑

这是file.js

var fs = require('fs');
function File() {
    function open(path, document) {
        function open(path, document) {
            fs.readFile(path, 'utf-8', function (error, contents) {
                document.getElementById('editor').value = contents;
            });
        }
    }
    function save(path, document) {
        function save(path, document) {
            var text = document.getElementById('editor').value;
            fs.writeFile(path, text);
        }
    }
    this.open = open;
    this.save = save;
}
module.exports = new File;

最佳答案

也许这不是 file.js 的错。

我构建了一个简单的项目,它可以与您的代码配合使用。

这是项目结构。顺便说一句,index.js 是您的所有代码。

Project
|-- index.html
|-- package.json
|-- node_modules
      |--File
         |--index.js

关于javascript - Node.js错误: "Unexpected token ;" while on node-webkit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22522817/

相关文章:

node.js - 无法在我的 docker 镜像中安装 bcrypt

javascript - 是否可以获得 node.js 正在服务的当前请求?

javascript - 无法实例化模块,AngularJS + NodeWebkit

javascript - 如何在 NodeWebkit 的 html 代码中访问从 Node 模块抓取的数据

javascript - Google Maps API 中的自定义 InfoWindow 大小/指针位置

javascript - 如何设置此 API 获取请求?

javascript - 嵌套类的范围问题

javascript - 类似 Facebook 的内容加载

node.js - 如何修复导出 'NotificationKind' 中未找到 'rxjs' 错误

javascript - 在 Node.js 和 node-webkit 中打开目录