最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

运维笔记admin19浏览0评论

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

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

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

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>

这是我的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');
});

我在做什么错?

回答如下:

您似乎要用encoding运行的文件似乎存在Node问题。有时,使用某些命令行实用工具创建的文件会对文件进行一些编码问题。因此,我建议不要使用它们来创建文件。只需使用Right-Click > New File > app.js创建文件,然后用app.js替换您的旧文件。并尝试运行node app.js

发布评论

评论列表(0)

  1. 暂无评论