Gulp3 node 10.16.3 globalThis - gulp

I tried to upgraded to gulp4 but now I need to go back to gulp3. I installed the node I had installed version 10.16.3 but now I am getting this error message? it was working in the past for me using this version so I am not sure what happen.
Angular CLI: 9.1.6
Node: 10.16.3
OS: win32 ia32
C:\WebProjects\ITF.Web>gulp prod
ReferenceError: globalThis is not defined
at Object. (C:\WebProjects\ITF.Web\node_modules\typedoc\dist\lib\utils\general.js:12:1)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object. (C:\WebProjects\ITF.Web\node_modules\typedoc\dist\lib\application.js:24:19)
at Module._compile (internal/modules/cjs/loader.js:778:30)
Gulp file
var gulp = require("gulp");
var runSequence = require("run-sequence");
var tslint = require("gulp-tslint");
var typedoc = require("gulp-typedoc");
var superstatic = require("superstatic");
var shell = require("gulp-shell");
var typescript = require("gulp-typescript");
var tsProject = typescript.createProject("tsconfig.json");
var sourcemaps = require("gulp-sourcemaps");
var rimraf = require("gulp-rimraf");
var replace = require("gulp-replace");
var rename = require("gulp-rename");
var ignore = require("gulp-ignore");
var insert = require("gulp-insert");
var concat = require("gulp-concat");
var uglify = require("gulp-uglify");
var tslintStylish = require("gulp-tslint-stylish");
var util = require("gulp-util");
var commentSwap = require("gulp-comment-swap");
var tsc = require("gulp-typescript");
var gulp_jspm = require("gulp-jspm");
var inlineNg2Template = require("gulp-inline-ng2-template");
/**
* Typescript configuration
**/
var paths = {
dist: "./dist",
sources: "./App/**/*.ts"
};
gulp.task("prod", function (callback) {
runSequence(
"compile",
"bundle",
"min",
function (error) {
if (error) {
console.log(error.message);
} else {
console.log("Production build finished successfully");
}
callback(error);
});
});
/**
* Compile TypeScript sources
*/
gulp.task("compile", ["clean"], function () {
return gulp.src("./App/**/*.ts")
.pipe(inlineNg2Template({
base: "/", // Angular2 application base folder
target: "es6", // Can swap to es5
indent: 2, // Indentation (spaces)
useRelativePaths: false, // Use components relative assset paths
removeLineBreaks: false, // Content will be included as one line
templateExtension: ".html", // Update according to your file extension
templateFunction: false // If using a function instead of a string for `templateUrl`, pass a reference to that function here
}))
.pipe(typescript(tsProject))
.pipe(ignore("References.js"))
.pipe(gulp.dest("dist/App"));
});
/**
* Bundle application parts
*/
gulp.task("bundle:template", function () {
return createBundleTask(paths.dist + "/App/Pages/TemplateEdit.js", "template");
});
gulp.task("bundle:agents", function () {
return createBundleTask(paths.dist + "/App/Pages/Maintenance/Agents.js", "agents");
});
gulp.task("bundle:indications", function () {
return createBundleTask(paths.dist + "/App/Pages/Maintenance/Indications.js", "indications");
});
gulp.task("bundle:styleguidenotes", function () {
return createBundleTask(paths.dist + "/App/Components/NoteEditor/NoteEditor.js", "styleguidenotes");
});
gulp.task("bundle:dynamicdictionary", function () {
return createBundleTask(paths.dist + "/App/Pages/Maintenance/DynamicDictionary.js", "dynamicdictionary");
});
gulp.task("bundle:splitdynamicdictionary", function () {
return createBundleTask(paths.dist + "/App/Pages/Maintenance/SplitDynamicDictionary.js", "splitdynamicdictionary");
});
gulp.task("bundle:styleguidenotesdevprocess", function () {
return createBundleTask(paths.dist + "/App/Pages/StyleGuideNote/Index.js", "styleguidenotesdevprocess");
});
gulp.task("bundle:scheduling", function () {
return createBundleTask(paths.dist + "/App/Pages/Scheduling/Index.js", "scheduling");
});
gulp.task("bundle:templatesmanagement", function () {
return createBundleTask(paths.dist + "/App/Pages/TemplatesManagement/Index.js", "templatesmanagement");
});
gulp.task("bundle:review", function () {
return createBundleTask(paths.dist + "/App/Pages/Review/Index.js", "review");
});
gulp.task("bundle:ownedreview", function () {
return createBundleTask(paths.dist + "/App/Pages/OwnedReview/Index.js", "ownedreview");
});
gulp.task("bundle:pdfqueue", function () {
return createBundleTask(paths.dist + "/App/Pages/PdfQueue/Index.js", "pdfqueue");
});
gulp.task("bundle:admin", function () {
return createBundleTask(paths.dist + "/App/Pages/Admin/Index.js", "admin");
});
gulp.task("bundle", function (callback) {
runSequence(
"bundle:template",
"bundle:agents",
"bundle:indications",
"bundle:styleguidenotes",
"bundle:dynamicdictionary",
"bundle:splitdynamicdictionary",
"bundle:styleguidenotesdevprocess",
"bundle:scheduling",
"bundle:templatesmanagement",
"bundle:review",
"bundle:ownedreview",
"bundle:pdfqueue",
"bundle:admin",
function (error) {
if (error) {
console.log(error.message);
} else {
console.log("Bundling finished successfully");
}
callback(error);
});
});
/**
* Create application package
*/
gulp.task("min:template", function () {
return createProductionPackageTask("template", true);
});
gulp.task("min:agents", function () {
return createProductionPackageTask("agents", false);
});
gulp.task("min:indications", function () {
return createProductionPackageTask("indications", false);
});
gulp.task("min:styleguidenotes", function () {
return createProductionPackageTask("styleguidenotes", false);
});
gulp.task("min:dynamicdictionary", function () {
return createProductionPackageTask("dynamicdictionary", false);
});
gulp.task("min:splitdynamicdictionary", function () {
return createProductionPackageTask("splitdynamicdictionary", false);
});
gulp.task("min:styleguidenotesdevprocess", function () {
return createProductionPackageTask("styleguidenotesdevprocess", false);
});
gulp.task("min:scheduling", function () {
return createProductionPackageTask("scheduling", false);
});
gulp.task("min:templatesmanagement", function () {
return createProductionPackageTask("templatesmanagement", false);
});
gulp.task("min:review", function () {
return createProductionPackageTask("review", false);
});
gulp.task("min:ownedreview", function () {
return createProductionPackageTask("ownedreview", false);
});
gulp.task("min:pdfqueue", function () {
return createProductionPackageTask("pdfqueue", false);
});
gulp.task("min:admin", function () {
return createProductionPackageTask("admin", false);
});
gulp.task("min", function (callback) {
runSequence(
"min:template",
"min:agents",
"min:indications",
"min:styleguidenotes",
"min:dynamicdictionary",
"min:splitdynamicdictionary",
"min:styleguidenotesdevprocess",
"min:scheduling",
"min:templatesmanagement",
"min:review",
"min:ownedreview",
"min:pdfqueue",
"min:admin",
function (error) {
if (error) {
console.log(error.message);
} else {
console.log("Minification finished successfully");
}
callback(error);
});
});
/**
* Clean build folder
*/
gulp.task("clean", function () {
return gulp.src(paths.dist, { read: false }).pipe(rimraf({ force: true }));
});
/**
* Helper methods
*/
var createBundleTask = function (entryPoint, packageId) {
if (typeof entryPoint === "undefined") {
throw "ArgumentNullException: entryPoint";
}
if (typeof packageId === "undefined") {
throw "ArgumentNullException: packageId";
}
var task = gulp.src(entryPoint)
.pipe(gulp_jspm({ selfExecutingBundle: true }))
.pipe(rename(packageId + ".bundle.js"))
.pipe(gulp.dest(paths.dist + "/bundle"));
return task;
};
var createProductionPackageTask = function (packageId, uglifyDestination) {
if (typeof packageId === "undefined") {
throw "ArgumentNullException: packageId";
}
var filesArry = [
"./node_modules/core-js/client/shim.min.js",
"./node_modules/zone.js/dist/zone.js",
"./node_modules/reflect-metadata/Reflect.js",
paths.dist + "/bundle/" + packageId + ".bundle.js"
];
var task = gulp.src(filesArry)
.pipe(concat(packageId + "_concatApp.js"))
.pipe(gulp.dest(paths.dist + "/temp"))
.pipe(rename(packageId + ".bundle.min.js"));
if (uglifyDestination) {
task = task.pipe(uglify({ mangle: false }));
}
return task.pipe(gulp.dest(paths.dist + "/build"));
};
Error installing typedoc#^2.2
PM> npm install -D 'typedoc#^2.2'
npm : npm ERR! code ETARGET
At line:1 char:1
+ npm install -D 'typedoc#^2.2'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (npm ERR! code ETARGET:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
npm ERR! notarget No matching version found for typedoc#2.2.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\AppData\Local\npm-cache\_logs\2022-04-18T12_02_53_816Z-debug-0.log
Debug log
128 verbose lifecycle nccn-cott#1.0.0~postinstall: unsafe-perm in lifecycle true
129 verbose lifecycle nccn-cott#1.0.0~postinstall: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\WebProjects\COTT\COTT\OrderTemplateTool.Web\node_modules\.bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\OpenSSL-Win64\bin;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files\dotnet\;C:\WINDOWS\System32\OpenSSH\;c:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;c:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft Emulator Manager\1.0\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files (x86)\dotnet\;C:\Program Files\nodejs\;D:\Ruby26-x64\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\;C:\Users\mcdevitt\AppData\Local\Programs\Fiddler;C:\Users\mcdevitt\AppData\Local\Microsoft\WindowsApps;C:\Users\mcdevitt\AppData\Roaming\npm
130 verbose lifecycle nccn-cott#1.0.0~postinstall: CWD: C:\WebProjects\COTT\COTT\OrderTemplateTool.Web
131 silly lifecycle nccn-cott#1.0.0~postinstall: Args: [ '/d /s /c', 'typings install' ]
132 timing audit submit Completed in 171ms
133 http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/audits/quick 172ms
134 timing audit body Completed in 2ms
135 silly lifecycle nccn-cott#1.0.0~postinstall: Returned: code: 1 signal: null
136 info lifecycle nccn-cott#1.0.0~postinstall: Failed to exec postinstall script
137 verbose stack Error: nccn-cott#1.0.0 postinstall: `typings install`
137 verbose stack Exit status 1
137 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
137 verbose stack at EventEmitter.emit (events.js:198:13)
137 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
137 verbose stack at ChildProcess.emit (events.js:198:13)
137 verbose stack at maybeClose (internal/child_process.js:982:16)
137 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
138 verbose pkgid nccn-cott#1.0.0

Support for Node.js 10 was dropped in TypeDoc 0.21 (see announcement). To keep using Node.js 10, pin gulp-typedoc to version 2.2:
npm install -D 'gulp-typedoc#^2.2'
gulp-typedoc 2.2.9 is the last version of gulp-typedoc that depends on a legacy version of TypeDoc, while gulp-typedoc 3.0 doesn't have a version requirement.

Related

AssertionError [ERR_ASSERTION]

I have gulp file that is having issues with latest update to gulp 4 I am getting assertion errors (AssertionError [ERR_ASSERTION]: Task function must be specified) and it seems (from googling) to have to do with how tasks are defined, but not sure if this is the case here and what needs to change.
Node: node -v
v14.16.0
CLI version: 2.3.0
Local version: 4.0.2
NPM: 6.14.11
Here is the code
// ### CSS processing pipeline
// Example
// ```
// gulp.src(cssFiles)
// .pipe(cssTasks('main.css')
// .pipe(gulp.dest(path.dist + 'styles'))
// ```
var cssTasks = function(filename) {
return lazypipe()
.pipe(function() {
return gulpif(!enabled.failStyleTask, plumber());
})
.pipe(function() {
return gulpif(enabled.maps, sourcemaps.init());
})
.pipe(function() {
return gulpif('*.less', less());
})
.pipe(function() {
return gulpif('*.scss', sass({
outputStyle: 'nested', // libsass doesn't support expanded yet
precision: 10,
includePaths: ['.'],
errLogToConsole: !enabled.failStyleTask
}));
})
.pipe(concat, filename)
.pipe(autoprefixer, {
browsers: [
'last 2 versions',
'android 4',
'opera 12'
]
})
.pipe(cssNano, {
safe: true
})
.pipe(function() {
return gulpif(enabled.rev, rev());
})
.pipe(function() {
return gulpif(enabled.maps, sourcemaps.write('.', {
sourceRoot: 'assets/styles/'
}));
})();
};
// ### JS processing pipeline
// Example
// ```
// gulp.src(jsFiles)
// .pipe(jsTasks('main.js')
// .pipe(gulp.dest(path.dist + 'scripts'))
// ```
var jsTasks = function(filename) {
return lazypipe()
.pipe(function() {
return gulpif(enabled.maps, sourcemaps.init());
})
.pipe(concat, filename)
.pipe(uglify, {
compress: {
'drop_debugger': enabled.stripJSDebug
}
})
.pipe(function() {
return gulpif(enabled.rev, rev());
})
.pipe(function() {
return gulpif(enabled.maps, sourcemaps.write('.', {
sourceRoot: 'assets/scripts/'
}));
})();
};
// ### Write to rev manifest
// If there are any revved files then write them to the rev manifest.
// See https://github.com/sindresorhus/gulp-rev
var writeToManifest = function(directory) {
return lazypipe()
.pipe(gulp.dest, path.dist + directory)
.pipe(browserSync.stream, {match: '**/*.{js,css}'})
.pipe(rev.manifest, revManifest, {
base: path.dist,
merge: true
})
.pipe(gulp.dest, path.dist)();
};
// ## Gulp tasks
// Run `gulp -T` for a task summary
// ### Styles
// `gulp styles` - Compiles, combines, and optimizes Bower CSS and project CSS.
// By default this task will only log a warning if a precompiler error is
// raised. If the `--production` flag is set: this task will fail outright.
gulp.task('styles', ['wiredep'], function() {
var merged = merge();
manifest.forEachDependency('css', function(dep) {
var cssTasksInstance = cssTasks(dep.name);
if (!enabled.failStyleTask) {
cssTasksInstance.on('error', function(err) {
console.error(err.message);
this.emit('end');
});
}
merged.add(gulp.src(dep.globs, {base: 'styles'})
.pipe(plumber({errorHandler: onError}))
.pipe(cssTasksInstance));
});
return merged
.pipe(writeToManifest('styles'));
});
// ### Scripts
// `gulp scripts` - Runs JSHint then compiles, combines, and optimizes Bower JS
// and project JS.
gulp.task('scripts', function() {
var merged = merge();
manifest.forEachDependency('js', function(dep) {
merged.add(
gulp.src(dep.globs, {base: 'scripts'})
.pipe(plumber({errorHandler: onError}))
.pipe(jsTasks(dep.name))
);
});
return merged
.pipe(writeToManifest('scripts'));
});
// ### Fonts
// `gulp fonts` - Grabs all the fonts and outputs them in a flattened directory
// structure. See: https://github.com/armed/gulp-flatten
gulp.task('fonts', function() {
return gulp.src(globs.fonts)
//.pipe(flatten())
.pipe(gulp.dest(path.dist + 'fonts'))
.pipe(browserSync.stream());
});
// ### Images
// `gulp images` - Run lossless compression on all the images.
gulp.task('images', function() {
return gulp.src(globs.images)
.pipe(imagemin([
imagemin.jpegtran({progressive: true}),
imagemin.gifsicle({interlaced: true}),
imagemin.svgo({plugins: [
{removeUnknownsAndDefaults: false},
{cleanupIDs: false}
]})
]))
.pipe(gulp.dest(path.dist + 'images'))
.pipe(browserSync.stream());
});
// ### JSHint
// `gulp jshint` - Lints configuration JSON and project JS.
gulp.task('jshint', function() {
return gulp.src([
'bower.json', 'gulpfile.js'
].concat(project.js))
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(gulpif(enabled.failJSHint, jshint.reporter('fail')));
});
// ### Clean
// `gulp clean` - Deletes the build folder entirely.
gulp.task('clean', require('del').bind(null, [path.dist]));
// ### Watch
// `gulp watch` - Use BrowserSync to proxy your dev server and synchronize code
// changes across devices. Specify the hostname of your dev server at
// `manifest.config.devUrl`. When a modification is made to an asset, run the
// build step for that asset and inject the changes into the page.
// See: http://www.browsersync.io
gulp.task('watch', function() {
browserSync.init({
files: ['{lib,templates}/**/*.php', '*.php'],
proxy: config.devUrl,
snippetOptions: {
whitelist: ['/wp-admin/admin-ajax.php'],
blacklist: ['/wp-admin/**']
}
});
gulp.watch([path.source + 'styles/**/*'], ['styles']);
gulp.watch([path.source + 'scripts/**/*'], ['scripts']);
gulp.watch([path.source + 'fonts/**/*'], ['fonts']);
gulp.watch([path.source + 'images/**/*'], ['images']);
gulp.watch(['bower.json', 'assets/manifest.json'], ['build']);
});
// ### Build
// `gulp build` - Run all the build tasks but don't clean up beforehand.
// Generally you should be running `gulp` instead of `gulp build`.
gulp.task('build', function(callback) {
runSequence('styles',
'scripts',
['fonts', 'images'],
callback);
});
// ### Wiredep
// `gulp wiredep` - Automatically inject Less and Sass Bower dependencies. See
// https://github.com/taptapship/wiredep
gulp.task('wiredep', function() {
var wiredep = require('wiredep').stream;
return gulp.src(project.css)
.pipe(wiredep())
.pipe(changed(path.source + 'styles', {
hasChanged: changed.compareSha1Digest
}))
.pipe(gulp.dest(path.source + 'styles'));
});
Any help is greatly appreciated.
So there are a few things wrong with your code.
gulp.task('styles', ['wiredep'], function() {
for example should be
gulp.task('styles', gulp.series('wiredep', function() { etc.
gulp.task only takes three arguments. You may have more places in your code like this.
gulp.watch([path.source + 'styles/**/*'], ['styles']); might actually be fine but lets be careful and make it a little more future-proof:
gulp.watch([path.source + 'styles/**/*'], gulp.series('styles'));
Etc. change all of these in your watch task.
With gulp.series and gulp.parallel you no longer need something like runSequence. So replace
gulp.task('build', function(callback) {
runSequence('styles',
'scripts',
['fonts', 'images'],
callback);
});
with
gulp.task('build', gulp.series(
'styles',
'scripts',
gulp.parallel('fonts', 'images')
// callback); // see below
);
Make these changes and you'll see if you need the `callback` in the `build` task - if you get a message about signaling async completion.
-----------
And you may have to move your `wiredep` task before your `styles` task. Since you are using `gulp.task` rather than functions to create your tasks, you cannot refer to a task that hasn't been created yet. That wouldn't be an issue if you used all named functions to create each task.

Task never defined: undefined

I used a similar configuration to another project (with more tasks) but I'm not sure what I'm missing here to get this error:
AssertionError [ERR_ASSERTION]: Task never defined: undefined
So would like to use Gulp 4 and use 3 tasks (build HTML, minify JavaScript, and create a server). I'm dividing it into 2 processes: dev and build.
const gulp = require('gulp');
const jsmin = require('gulp-jsmin');
const browserSync = require('browser-sync').create();
function jsMinify () {
return gulp.src('./src/**/*.js')
.pipe(jsmin())
.pipe(gulp.dest('./dist'))
}
function buildHTML () {
return gulp.src('./src/html/**/*.html')
.pipe(gulp.dest('./dist'))
}
function buildServe () {
browserSync.init({
server: {
baseDir: "./dist/",
},
port: 9001
});
}
function watch (){
browserSync.init({
server: {
baseDir: "./src/",
},
port: 8080
});
gulp.watch('./src/**/*.html').on('change', browserSync.reload);
gulp.watch('./src/**/*.js').on('change', browserSync.reload);
};
const dev = gulp.series(watch);
const build = gulp.series(
gulp.parallel(buildHTML, jsMinify),
buildServe()
);
exports.dev = dev;
exports.build = build;
Am I missing something about Gulp 4 or this code should run without any issue?
This is an error:
const build = gulp.series(
gulp.parallel(buildHTML, jsMinify),
buildServe() // <= error here, don't call the function just list it like below
);
const build = gulp.series(
gulp.parallel(buildHTML, jsMinify),
buildServe // <= removed ()
);
gulp.series() arguments are function names or task names. By using buildServe() I imagine that it is returning undefined hence your error message about undefined never being defined as a task. I hope that makes sense.
[I haven't been able to test this change yet to see if it fixes your issue, but I don't see any other problems in your code.]

Google cloud functions - cannot read property 'getApplicationDefault'

I have deployed a cloud function to invoke a dataflow pipeline template and trying to trigger the function by placing the file in cloud storage bucket.
As node.js prerequisite I have done,
npm init
npm install --save googleapis
Index.js
const google = require('googleapis');
exports.goWithTheDataFlow = function(event, callback) {
const file = event.data;
google.auth.getApplicationDefault(function (err, authClient, projectId) {
if (err) {
throw err;
}
console.log(projectId);
if (authClient.createScopedRequired && authClient.createScopedRequired()) {
authClient = authClient.createScoped([
'https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/userinfo.email'
]);
}
const dataflow = google.dataflow({ version: 'v1b3', auth: authClient });
console.log(`gs://${file.bucket}/${file.name}`);
dataflow.projects.templates.create({
projectId: projectId,
resource: {
parameters: {
inputFile: `gs://${file.bucket}/${file.name}`
},
jobName: 'cloud-fn-dataflow-test',
gcsPath: 'gs://jaison/templates/ApacheBeamTemplate'
}
}, function(err, response) {
if (err) {
console.error("problem running dataflow template, error was: ", err);
}
console.log("Dataflow template response: ", response);
callback();
});
});
callback();
};
Command used to deploy cloud function:
gcloud beta functions deploy goWithTheDataFlow --stage-bucket cf100stage --trigger-bucket cf100
Dataflow(Apache beam):
I was able to execute the dataflow template from console and below is the path of the template,
'gs://jaison/templates/ApacheBeamTemplate'
Function crashes with below error:
TypeError: Cannot read property 'getApplicationDefault' of undefined
at exports.goWithTheDataFlow (/user_code/index.js:11:17) at
/var/tmp/worker/worker.js:695:16 at /var/tmp/worker/worker.js:660:9 at
_combinedTickCallback (internal/process/next_tick.js:73:7) at process._tickDomainCallback (internal/process/next_tick.js:128:9)
Looks like I am missing libraries. Not sure how to fix this. Please help.
My cloud function works with below changes,
1.Setting up GOOGLE_APPLICATION_CREDENTIALS to service account json file
export GOOGLE_APPLICATION_CREDENTIALS="/path/of/svc/json/file.json"
2.index.js
var {google} = require('googleapis');
exports.TriggerBeam = (event, callback) => {
const file = event.data;
const context = event.context;
console.log(`Event ${context.eventId}`);
console.log(` Event Type: ${context.eventType}`);
console.log(` Bucket: ${file.bucket}`);
console.log(` File: ${file.name}`);
console.log(` Metageneration: ${file.metageneration}`);
console.log(` Created: ${file.timeCreated}`);
console.log(` Updated: ${file.updated}`);
google.auth.getApplicationDefault(function (err, authClient, projectId) {
if (err) {
throw err;
}
console.log(projectId);
const dataflow = google.dataflow({ version: 'v1b3', auth: authClient });
console.log(`gs://${file.bucket}/${file.name}`);
dataflow.projects.templates.create({
projectId: projectId,
resource: {
parameters: {
inputFile: `gs://${file.bucket}/${file.name}`
},
jobName: 'cloud-fn-beam-test',
gcsPath: 'gs://jaison/templates/ApacheBeamTemplate'
}
}, function(err, response) {
if (err) {
console.error("problem running dataflow template, error was: ", err);
}
console.log("Dataflow template response: ", response);
callback();
});
});
callback();
};

'TypeError: dest.end is not a function' when trying to import rxjs

I'm new to both Gulp and Browserify and I'm working on a Typescript project. Everything worked
fine till I imported rxjs but since then I'm facing with the following error message:
d:\Work\rxjsnew\node_modules\gulp\node_modules\vinyl-fs\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:523
dest.end();
^
TypeError: dest.end is not a function
at DestroyableTransform.onend (d:\Work\rxjsnew\node_modules\gulp\node_modules\vinyl-fs\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:523:10)
at DestroyableTransform.g (events.js:260:16)
at emitNone (events.js:72:20)
at DestroyableTransform.emit (events.js:166:7)
at d:\Work\rxjsnew\node_modules\gulp\node_modules\vinyl-fs\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:965:16
at nextTickCallbackWith0Args (node.js:419:9)
at process._tickCallback (node.js:348:13)
If I remove the rxjs import, the project is compiled successfully.
This is my gulpfile:
var gulp = require("gulp");
var browserify = require("browserify");
var source = require('vinyl-source-stream');
var tsify = require("tsify");
gulp.task('scripts', function () {
return gulp.src('js/*.js')
.pipe(browserify().on('error', function(e){
console.log(e);
}));
});
gulp.task("default", ["scripts"], function () {
return browserify({
basedir: '.',
debug: true,
entries: ['src/main.ts'],
cache: {},
packageCache: {}
})
.plugin(tsify)
.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest("dist"))
});
Installing '#reactivex/rxjs' package and importing Rx the following way solved the issue.
import { Observable } from '#reactivex/rxjs';

Browserify fails to create bundle with babelify transform (TypeError: Path must be a string.)

I've written a gulp task to compile my .jsx and .js scripts into a bundle using watchify and babelify as a transform. For some reason my gulp script seems to be choking on the transform and I'm not sure why:
gulp.task('browserify', function() {
var bundle = watchify(browserify('./app/jsx/client/index.jsx', {
extensions: ['.js', '.jsx'],
debug: process.env.NODE_ENV === 'development'
}));
bundle.transform(babelify);
bundle.on('update', function() {
rebundle(bundle);
});
function rebundle(bundle) {
return bundle.bundle()
.on('error', function(error) {
console.log(error.stack, error.message);
this.emit('end');
})
.pipe(
gulpif(
(process.env.NODE_ENV == 'production'),
require('gulp-rename')('bundle.min.js'),
require('gulp-rename')('bundle.js')
)
)
.pipe(gulpif((process.env.NODE_ENV == 'production'), buffer()))
.pipe(gulpif((process.env.NODE_ENV == 'production'), uglify()))
.pipe(gulp.dest('dist/js'));
}
return rebundle(bundle);
});
In the console...
path.js:8
throw new TypeError('Path must be a string. Received ' +
^
TypeError: Path must be a string. Received undefined
at assertPath (path.js:8:11)
at Object.posix.join (path.js:480:5)
at Transform.stream._transform (/home/zipp/search-admin/node_modules/gulp-rename/index.js:52:22)
at Transform._read (_stream_transform.js:167:10)
at Transform._write (_stream_transform.js:155:12)
at doWrite (_stream_writable.js:292:12)
at writeOrBuffer (_stream_writable.js:278:5)
at Transform.Writable.write (_stream_writable.js:207:11)
at Readable.ondata (/home/zipp/search-admin/node_modules/browserify/node_modules/read-only-stream/node_modules/readable-stream/lib/_stream_readable.js:572:20)
at emitOne (events.js:77:13)
at Readable.emit (events.js:169:7)
That error is because you need a vinyl-source-stream in there. The result of .bundle() is a standard Node stream of file data. You are taking that data are passing it to rename which expects a stream of Gulp File objects.
var source = require('vinyl-source-stream');
// stuff
function rebundle(bundle) {
return bundle.bundle()
.on('error', function(error) {
console.log(error.stack, error.message);
this.emit('end');
})
.pipe(
gulpif(
(process.env.NODE_ENV == 'production'),
// Use 'source' here instead, which converts binary
// streams to file streams.
source('bundle.min.js'),
source('bundle.js')
)
)
.pipe(gulpif((process.env.NODE_ENV == 'production'), buffer()))
.pipe(gulpif((process.env.NODE_ENV == 'production'), uglify()))
.pipe(gulp.dest('dist/js'));
}
Instead of using rename, you can use source to define the initial name of the file.