【问题标题】:repl node js problem SyntaxError: Unexpected identifierrepl node js问题 SyntaxError: Unexpected identifier
【发布时间】:2019-02-17 07:52:51
【问题描述】:

https://repl.it/@doadhdoadh/IdleAccurateSource

const express        = require('express');
const MongoClient    = require('mongodb').MongoClient;
const bodyParser     = require('body-parser');
const app            = express();
const port = 8000;
app.use(bodyParser.urlencoded({ extended: true }));
require('./app/routes')(app, {});
app.listen(port, () => {
  console.log('We are live on ' + port);
});



node v9.7.1 linux/amd64
   npm dev
evalmachine.<anonymous>:1
npm dev
    ^^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:51:7)
    at createScript (vm.js:136:10)
    at Object.runInContext (vm.js:181:10)
    at evaluate (/run_dir/repl.js:133:14)
    at ReadStream.<anonymous> (/run_dir/repl.js:116:5)
    at ReadStream.emit (events.js:180:13)
    at addChunk (_stream_readable.js:274:12)
    at readableAddChunk (_stream_readable.js:261:11)
    at ReadStream.Readable.push (_stream_readable.js:218:10)
    at fs.read (fs.js:2124:12)

【问题讨论】:

    标签: javascript html node.js mongodb express


    【解决方案1】:

    我浏览了原始的 server.js 文件,发现您在第 12 行缺少分号,即 db = database.db("api");

    更新

    我刚刚意识到 repl NodeJs 演示是使用 index.js 文件触发的。我只是在 server.js 中导出了一个函数,然后在 index.js 中导入它来触发服务器创建过程。

    查看the updated poc

    希望它有效!

    【讨论】:

    • 谢谢你的回复,但是当我在终端运行 npm dev 时,我仍然看到错误,你能告诉我如何解决它
    • 你能试试npm run dev吗? package.json 脚本使用 npm run script_name 命令运行。
    • 嘿,我仍然看到这个错误意外标识符...你能在 repl 终端中运行它吗
    • 你有什么办法可以帮助我
    • 似乎 repl NodeJs 应用程序被index.js 文件触发。检查更新的项目。我仍在尝试弄清楚如何使用nodemon..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-25
    • 2019-10-06
    • 2021-06-09
    • 1970-01-01
    • 2017-11-15
    • 1970-01-01
    • 2017-10-13
    相关资源
    最近更新 更多