@zingerrrr

Почему не запускается код?

После того как я добавил в html небольшую форму, появилась эта ошибка.
gulp
/home/coda/Documents/gulp-test/gulpfile.js:33
fileinclude = require("gulp-file-include"),
^

SyntaxError: Identifier 'fileinclude' has already been declared
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at requireOrImport (/usr/local/lib/node_modules/gulp/node_modules/gulp-cli/lib/shared/require-or-import.js:19:11)
at execute (/usr/local/lib/node_modules/gulp/node_modules/gulp-cli/lib/versioned/^4.0.0/index.js:37:3)

вот сам код
const fileinclude = require('gulp-file-include');

let project_folder = "dist";
let source_folder = "#src"

let path = {
build:{
html: project_folder + "/",
css: project_folder + "/css/",
js: project_folder + "/js/",
img: project_folder + "/img/",
fonts: project_folder + "/fonts/",
},
src: {
html: [source_folder + "/*.html", "!" + source_folder + "/_*.html"],
css: source_folder + "/scss/style.scss",
js: source_folder + "/js/script.js",
img: source_folder + "/img/**/*.{jpg,png,svg,gif,ico,webp}",
fonts: source_folder + "/fonts/*.ttf",
},
watch: {
html: source_folder + "/**/*.html",
css: source_folder + "/scss/**/*.scss",
js: source_folder + "/js/**/*.js",
img: source_folder + "/img/**/*.{jpg,png,svg,gif,ico,webp}",
},
clean: "./" + project_folder + "/"
}

let { src, dest } = require('gulp'),
gulp = require('gulp'),
browsersync = require("browser-sync").create(),
fileinclude = require("gulp-file-include"),
del = require("del"),
scss = require("gulp-sass");

function browserSync(params) {
browsersync.init({
server:{
baseDir: "./" + project_folder + "/"
},
port:3000,
notify:false
})
}

function html() {
return src(path.src.css)
.pipe(dest(path.build.css))
.pipe(browsersync.stream())
}

function css() {
return src(path.src.css)
.pipe(
scss({
outputStyle: "expanded"
})
)
.pipe(dest(path.build.css))
.pipe(browsersync.stream())
}

function watchFiles(params) {
gulp.watch([path.watch.html], html);
}

function clean(params) {
return del(path.clean);
}

let build = gulp.series(clean, gulp.parallel(css, html));
let watch = gulp.parallel(build, watchFiles, browserSync);

exports.css = css;
exports.html = html;
exports.build = build;
exports.watch = watch;
exports.default = watch;
  • Вопрос задан
  • 122 просмотра
Решения вопроса 1
@Asokr
Вы два раза объявили переменную fileinclude
SyntaxError: Identifier 'fileinclude' has already been declared

В начале
const fileinclude = require('gulp-file-include');
И затем еще раз
let { src, dest } = require('gulp'),
gulp = require('gulp'),
browsersync = require("browser-sync").create(),
fileinclude = require("gulp-file-include"),
del = require("del"),
scss = require("gulp-sass");


Именно это и указано в ошибке.
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы