gpt4 book ai didi

javascript - createScript (vm.js :56:10) Node js when running gulp dev only on windows 处出现意外标记)

转载 作者:太空宇宙 更新时间:2023-11-04 00:15:10 26 4
gpt4 key购买 nike

SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\server\index.js:2:13)

当我运行 gulp dev 时收到此错误这种情况只发生在windows上,在linux下运行良好,服务器正在linux上启动

以下是片段

const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');

const routes = require('./routes');

mongoose.connect('mongodb://localhost/testdb');
const dbConnection = mongoose.connection;
dbConnection.on(
'error',
console.error.bind(console, 'Connection Error:')
);
dbConnection.once(
'open',
() => {
console.log('DB connection successful');
}
);

我在第 12 行收到此错误,

但是当我这样写时我不会收到任何错误并且服务器启动

const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');

const routes = require('./routes');

mongoose.connect('mongodb://localhost/ecommerce');
const dbConnection = mongoose.connection;
dbConnection.on('error', console.error.bind(console, 'Connection Error:'));
dbConnection.once('open',()=>{console.log('DB connection successful');});

这背后的原因是什么?

最佳答案

我有同样的问题,所以我只是删除了导致错误的代码块,然后重写它,我认为这是由于一些隐藏字符造成的

关于javascript - createScript (vm.js :56:10) Node js when running gulp dev only on windows 处出现意外标记),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47512166/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com