我不断收到错误消息“ Identifier'browserSync'已经被声明”,但我看不出问题出在哪里。这是我的代码
// Watch files
function watchFiles() {
gulp.watch("*.js", gulp.series(scriptsLint, scripts, browserSyncReload));
gulp.watch(["processHTML"], gulp.series(browserSyncReload));
}
//Task Live Reload
function browserSync(done) {
browserSync.init({
server: './dist',
port: 8080,
ui: {
port: 8081
}
})
done()
};
// BrowserSync Reload
function browserSyncReload(done) {
browserSync.reload();
done();
}
// define complex tasks
const js = gulp.series(scriptsLint, scripts);
const build = gulp.parallel(processHTML,js);
const watch = gulp.parallel(watchFiles, browserSync);
答案 0 :(得分:1)
您需要将函数browserSync
重命名为其他名称,因为这是为BrowserSync库保留的关键字。
类似这样的东西:
// Watch files
function watchFiles() {
gulp.watch("*.js", gulp.series(scriptsLint, scripts, reload));
gulp.watch(["processHTML"], gulp.series(reload));
}
//Task Live Reload
function localServer(done) {
browserSync.init({
server: './dist',
port: 8080,
ui: {
port: 8081
}
})
done()
};
// BrowserSync Reload
function reload(done) {
browserSync.reload();
done();
}
// define complex tasks
const js = gulp.series(scriptsLint, scripts);
const build = gulp.parallel(processHTML,js);
const watch = gulp.parallel(watchFiles, localServer);
答案 1 :(得分:-1)
您在第9行声明的var fs = require("fs");
var bankAccount = fs.readFileSync("bank.txt","UTF-8");
let inputString = process.argv;
let action = inputString[2];
let amount = inputString[3];
const DELIMITER = ' ';
if(action == "deposit"){
deposit();
}else if(action == "withdraw"){
withdraw();
}else if(action == "total"){
total();
}else if(action == "lotto"){
lotto();
}else{
console.log("Please input whether it is a deposit, withdraw, total, or you wanna try the lotto?");
}
function total() {
const transactions = bankAccount.split(DELIMITER)
sum = 0;
for(let i=0; i < transactions.length; i++){
sum+= Number(transactions[i]);
}
console.log(sum);
}
function deposit() {
fs.appendFileSync("bank.txt", DELIMITER + amount);
}
函数在其作用域browserSync()
(在第10行)中的名称与另一个变量相同,并且需要重命名。
browserSync