js vm报错,SyntaxError:createScript处的无效或意外令牌(vm.js:80:10)

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

node app.js

I am getting the following exception:

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>

Here's my source for 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');

});

What am I doing wrong?

解决方案

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.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值