SyntaxError:createScript处的无效或意外令牌(vm.js:80:10) [英] SyntaxError: Invalid or unexpected token at createScript (vm.js:80:10)

查看:2703
本文介绍了SyntaxError:createScript处的无效或意外令牌(vm.js:80:10)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想学习节点,当从powershell终端执行一个非常简单的应用程序时:

I've just arted to learn node, and when executing a very simple app from a powershell terminal:

node app.js

我收到以下异常:

SyntaxError: Invalid or unexpected token
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:607:28)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
PS C:\Users\kisco\Source\Repos\library> node app.js
C:\Users\kisco\Source\Repos\library\app.js:1
(function (exports, require, module, __filename, __dirname) { ��v
                                                              ^

SyntaxError: Invalid or unexpected token
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:607:28)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
PS C:\Users\kisco\Source\Repos\library>

这是<$ c $的来源c> app.js :

var express = require('express');

var app = express();

app.get('/', function(req, res){
    res.send('Hello from my libvrary app')
})

app.listen(3000, function(){
    console.log('listening on port 3000');
});

我做错了什么?

推荐答案

看起来您尝试运行的文件存在一些编码问题节点。有时,使用某个命令行实用程序创建的文件会对文件产生一些编码问题。所以,我建议不要用它们来创建文件。只需使用右键单击>创建文件即可新文件> app.js 并用此 app.js 替换旧文件。并尝试运行节点app.js

It looks like there is some encoding issue with the file that you're trying to run with Node. Sometimes, files created with some command line utility does some encoding issues with the file. So, I would suggest not to use them to create file. Just create file with Right-Click > New File > app.js and replace your old file with this app.js. And try running node app.js.

这篇关于SyntaxError:createScript处的无效或意外令牌(vm.js:80:10)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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