我正在设置一个Gulp文件来运行其他任务,但是在尝试运行默认任务时出现此错误(请参见下文)。我试图编译sass,js和html并添加browserSync和一些额外的功能。
internal/modules/cjs/loader.js:631
throw new ERR_INVALID_ARG_TYPE('id', 'string', id);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received type undefined
at Module.require (internal/modules/cjs/loader.js:631:11)
at String.require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/Users/DaneCaleeArni/Sites/starter/gulpfile.js:8:23)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
//这是我的gulp文件,其中包含所有任务
//Require all needed components
var gulp = require ('gulp')
var sass = require('gulp-sass')
sass.compiler = require('node-sass')
var browserSync = require('browser-sync').create()
var cleanCss = require('gulp-clean-css')
var sourcemaps = require('gulp-sourcemaps')
var webpack = require.apply('webpack-stream')
var autoprefixer = require('gulp-autoprefixer')
//Output HTML to dist folder
gulp.task('html', function() {
gulp.src('src/*.html')
.pipe(gulp.dest('dist'))
})
//Put fonts in dist folder
gulp.task('fonts', function() {
return gulp.src('src/fonts/*')
.pipe(gulp.dest('dist/fonts'))
})
//Put images in dist folder
gulp.task('images', function() {
return gulp.src('src/img/*')
.pipe(imagemin())
.pipe(gulp.dest('dist/img'))
})
//Run Sass
gulp.task('sass', function(){
return gulp.src('src/sass/style.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(
cleanCss({
compatibility: 'ie8'
})
)
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist'))
.pipe(browserSync.stream())
})
//Run JS through webpack and output to dist + browserSync
gulp.task('js', function() {
gulp.src('src/js/*')
.pipe(
webpack({
mode: 'production',
devtool: 'source-map',
output: {
filename: 'main.js'
}
}))
.pipe(gulp.dest('dist/js'))
.pipe(browserSync.stream())
})
//Browsersync and watch
gulp.task('watch', function() {
browserSync.init({
server: {
baseDir: './dist'
}
})
gulp.watch('src/*.html',['html'])
.on('change', browserSync.reload)
gulp.watch('src/js/*',['js'])
gulp.watch('src/sass/style.scss', ['sass'])
gulp.watch('src/fonts/*', ['fonts'])
gulp.watch('src/img/*', ['images'])
})
//Default Gulp task
gulp.task('default', ['html', 'sass', 'fonts', 'images', 'js', 'watch'])
我已经尝试过在终端中重新安装npm,但是没有运气。抱怨的是loader.js和helpers.js?