Gulp-浏览器同步返回错误

问题描述 投票:0回答:1

我正在尝试设置gulp以在通过在线教程保存更改时自动刷新项目。

每次启动“ gulp服务”时,它都会不断抛出错误

版本

node version - v12.13.0
npm version - 6.13.0
gulp version - 3.9.1

我的gulpfile.js代码:

var gulp = require('gulp');
var uglifycss = require('gulp-uglifycss');
var sass = require('gulp-sass');
var browserSync = require('browser-sync').create();
sass.compiler = require('node-sass');

gulp.task('sass', function () {
    return gulp.src('./sass/**/*.scss')
        .pipe(sass().on('error', sass.logError))
        .pipe(gulp.dest('./css'));
});

gulp.task('sass:watch', function () {
    gulp.watch('./sass/**/*.scss', ['sass']);
});

gulp.task('css', function () {
 gulp.src('./styles/**/*.css')
  .pipe(uglifycss({
   "maxLineLen": 80,
   "uglyComments": true
}))
.pipe(gulp.dest('./dist/'));
}); 

gulp.task('serve', ['sass'], function() {

browserSync.init({
    server: "./app"
});

gulp.watch("app/scss/*.scss", ['sass']);
gulp.watch("app/*.html").on('change', browserSync.reload);
});

gulp.task('browser-sync', function() {
    browserSync.init({
    server: {
        baseDir: "./"
        }
    });
});

gulp.task('js', function () {
    return gulp.src('js/*js')
        .pipe(browserify())
        .pipe(uglify())
        .pipe(gulp.dest('dist/js'));
});

gulp.task('js-watch', ['js'], function (done) {
    browserSync.reload();
    done();
});

gulp.task('default', ['js'], function () {
     browserSync.init({
        server: {
            baseDir: "./"
        }
    });
gulp.watch("js/*.js", ['js-watch']);
});

我的[[package.json代码:

{ "name": "fifteen-projects", "version": "1.0.0", "description": "Project files", "main": "gulpfile.js", "dependencies": { "gulp-uglifycss": "^1.1.0" }, "devDependencies": { "browser-sync": "^2.26.7", "gulp": "^3.9.1", "gulp-sass": "^4.0.2", "node-sass": "^4.13.0" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url": "git+https://github.com/MarvinBrereton-creator/fifteen-projects.git" }, "author": "Marvin Brereton", "license": "MIT", "bugs": { "url": "https://github.com/MarvinBrereton-creator/fifteen-projects/issues" }, "homepage": "https://github.com/MarvinBrereton-creator/fifteen-projects#readme" }
当我在gulp所在的项目文件夹中的cmd中启动“ 

gulp服务

”时,它会返回:fs.js:27const { Math, Object } = primordials; ReferenceError: primordials is not defined at fs.js:27:26 at req_ (C:\Users\kk\Documents\GitHub\fifteen-projects\node_modules\natives\index.js:143:24) at Object.req [as require] (C:\Users\kk\Documents\GitHub\fifteen- projects\node_modules\natives\index.js:55:10) at Object.<anonymous> (C:\Users\kk\Documents\GitHub\fifteen-projects\node_modules\vinyl- fs\node_modules\graceful-fs\fs.js:1:37) at Module._compile (internal/modules/cjs/loader.js:956:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10) at Module.load (internal/modules/cjs/loader.js:812:32) at Function.Module._load (internal/modules/cjs/loader.js:724:14) at Module.require (internal/modules/cjs/loader.js:849:19) at require (internal/modules/cjs/helpers.js:74:18)
[我认为问题出在Node_modules文件夹中,因为每当我尝试启动gulpfile.js时错误都出自那里

    感谢您的帮助,谢谢!
gulp
1个回答
0
投票
我发现最好的方法是在VsCode中使用内置扩展名(热重载)。 Gulp已经过时了。
© www.soinside.com 2019 - 2024. All rights reserved.