[英]Node.js error: “Unexpected token ;” while on node-webkit
我試圖按照本教程在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
file:///Users/Gonzo/Documents/node-webkit-v0.9.2-osx-ia32/js/main.js:1:12
檢出main.js
文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.