我试图关注 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/