Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
619 views
in Technique[技术] by (71.8m points)

javascript - SyntaxError: Invalid or unexpected token at 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:UserskiscoSourceReposlibrary> node app.js
C:UserskiscoSourceReposlibraryapp.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:UserskiscoSourceReposlibrary>

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...