gpt4 book ai didi

Node.js 和 Gulp 帮助

转载 作者:太空宇宙 更新时间:2023-11-03 22:07:34 25 4
gpt4 key购买 nike

美好的一天,我是 Gulp 和 Node Js 的新手,我一直收到此错误(如下所示),我做了一些研究,但没有找到任何修复。

 [Browserslist] Could not parse /Users/gendyblackman/Sites/blackmanimages/package.json. Ignoring it.

assert.js:269 抛出错误;

断言错误[ERR_ASSERTION]:任务从未定义:干净

at getFunction (/Users/gendyblackman/Sites/blackmanimages/node_modules/undertaker/lib/helpers/normalizeArgs.js:15:5)
at map (/Users/gendyblackman/Sites/blackmanimages/node_modules/arr-map/index.js:20:14)
at normalizeArgs (/Users/gendyblackman/Sites/blackmanimages/node_modules/undertaker/lib/helpers/normalizeArgs.js:22:10)
at Gulp.series (/Users/gendyblackman/Sites/blackmanimages/node_modules/undertaker/lib/series.js:13:14)
at Object.<anonymous> (/Users/gendyblackman/Sites/blackmanimages/gulpfile.js:115:9)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)

此外,当我在本地重新安装 Gulp 时,我收到这些错误,如下所示。

npm ERR! file /Users/gendyblackman/Sites/blackmanimages/package.json

npm ERR! code EJSONPARSE

npm ERR! JSON.parse Failed to parse json

npm ERR! JSON.parse Unexpected string in JSON at position 734 while parsing '{

npm ERR! JSON.parse "name": "blackmanimages",

npm ERR! JSON.parse "version'

npm ERR! JSON.parse Failed to parse package.json data.

npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

npm ERR! A complete log of this run can be found in:

npm ERR! /Users/gendyblackman/.npm/_logs/2018-07-05T14_56_20_043Z-debug.log

任何帮助都会很棒。谢谢,

另外,这是我的 Gulpfile.js

// Compiles all SASS files
gulp.task('scss', function () {
return gulp.src('source/scss/**/*.scss')
.pipe(plumber())
.pipe(scss({
style: 'compressed',
}))
.pipe(rename({
basename: 'main',
suffix: '.min',
}))

.pipe(gulp.dest('build/assets/css'))
.pipe(browserSync.stream());
});



//Optimizing Images
gulp.task('images', function (){
return gulp.src('source/img/**/*.+(png|jpg|gif|svg)')
.pipe(cache(imagemin({
interlaced: true
})))
.pipe(gulp.dest('build/assets/img'))
});

// Uglify js files
gulp.task('scripts', function () {
gulp.src('source/js/*.js')
.pipe(plumber())
.pipe(uglify())
.pipe(gulp.dest('build/assets/js'))
.pipe(browserSync.stream());
});

//Concat and Compress Vendor .js files
gulp.task('vendors', function () {
gulp.src(
[
'source/js/vendors/jquery.min.js',
'source/js/vendors/*.js',
])
.pipe(plumber())
.pipe(concat('vendors.js'))
.pipe(uglify())
.pipe(gulp.dest('build/assets/js'));
});

// Watch for changes
gulp.task('watch', function () {
//Serve files from the root of this project
browserSync.init({
server: {
baseDir: "./build",
},
notify: false
});

gulp.watch(styleSrc, ['scss']);
gulp.watch(scriptSrc, ['scripts']);
gulp.watch(vendorSrc, ['vendors']);
gulp.watch(['build/*.html', 'build/assets/css/*.css', 'build/assets/js/*.js', 'build/assets/js/vendors/*.js' , '/build/assets/img/*' , '/build/assets/img/'])
.on(' change ', browserSync.reload);

});

//use default task to launch Browsersync and watch JS files
gulp.task('default',gulp.series('clean',gulp.parallel('scss', 'scripts', 'vendors',`images`,`fonts`, 'watch'), function (){
console.log('Building files');
}));



gulp.task('default', [ 'sass', 'scripts', 'vendors', 'watch'], function () );


gulp.task('default', function (callback) {runSequence(['sass','browserSync', 'watch'],callback)});

package.json

{
"name": "blackmanimages",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},

"author": "",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.24.5",
"del": "^3.0.0",
"express": "^4.16.3",
"gulp": "github:gulpjs/gulp#4.0",
"gulp-autoprefixer": "^5.0.0",
"gulp-cache": "^1.0.2",
"gulp-compass": "^2.1.0",
"gulp-imagemin": "^4.1.0",
"gulp-mamp": "0.0.5",
"gulp-minify-css": "^1.2.4",
"gulp-plumber": "^1.2.0",
"gulp-rename": "^1.2.3",
"gulp-sass": "^4.0.1",
"gulp-sourcemaps": "^2.6.4",
"minimatch": "^3.0.2",
"mysql": "^2.15.0",
"run-sequence": "^2.2.1"
"gulp-concat": "^2.6.1",
"gulp-contrib-copy": "0.1.3",
"gulp-cssnano": "^2.1.3",
"gulp-scss": "^1.4.0",
"gulp-uglify": "^3.0.0",
"gulp-useref": "^3.1.5"
},
"dependencies": {}
}

最佳答案

错误:

JSON.parse package.json must be actual JSON

你的package.json是正确的JSON格式。

检查这一行:

"run-sequence": "^2.2.1"

, 添加到该行末尾。

您没有定义任务clean,但您调用了它:

gulp.task('default',gulp.series('clean',gulp.parall .....

您应该删除它或创建clean

require('gulp-cache') 但您将其从 package.json 中删除了。

检查环境变量NODE_ENV是否为生产?如果属实,请将其删除。 (因为如果 NODE_ENV生产,则不会安装 devDependency)

关于Node.js 和 Gulp 帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51327043/

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