节点REPL抛出SyntaxError:意外的标识符 [英] Node REPL throws SyntaxError: Unexpected identifier

查看:137
本文介绍了节点REPL抛出SyntaxError:意外的标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对node.js非常新手。在节点REPL中一切正常。但有些改变。当我尝试执行一个文件时,它显示了这个...

I am very newbie to node.js. In the node REPL everything was working fine. But something changed. When I try to execute a file it shows this...

D:\Projects-2015\uniqueva>node
/>node module.js


SyntaxError: Unexpected identifier
    at Object.exports.createScript (vm.js:44:10)
    at REPLServer.defaultEval (repl.js:117:23)
    at bound (domain.js:254:14)
    at REPLServer.runBound [as eval] (domain.js:267:12)
    at REPLServer.<anonymous> (repl.js:279:12)
    at REPLServer.emit (events.js:107:17)
    at REPLServer.Interface._onLine (readline.js:214:10)
    at REPLServer.Interface._line (readline.js:553:8)
    at REPLServer.Interface._ttyWrite (readline.js:830:14)
    at ReadStream.onkeypress (readline.js:109:10)

这种情况即使在我尝试这种情况时也会发生......

It happens even when I try this...

node --version

我有以下代码在module.js中。

I have the following code in the module.js..

var http = require("http");

http.createServer(function(request, response){
    response.writeHead(200, {"Content-Type" : "text/plain"});
    response.write("Hello World");
    response.end();
}).listen(8888);

..但是即使我只尝试使用console.log,或者只是将文件留空同样的问题..

..but even if I try to only console.log something, or just leave the file blank it's the same issue..

推荐答案

您无法在节点REPL中调用节点可执行文件...仅限JavaScript语句/表达式。

You can't call the node executable from within the node REPL... Only JavaScript statements/expressions.

试试 require('./ module.js')

这篇关于节点REPL抛出SyntaxError:意外的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆