klei/gulp-inject

Inject fails for version 4.2.0

chaitanyavangoori opened this issue · 12 comments

Hello, inject seems to fail suddenly without any change in the task. This is the error I which I am facing,

(node:51098) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'startTag' of undefined
(node:51098) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

My gulp task:
`gulp.task('update:index', function () {
var target = gulp.src('./app/index.html');

var injectOptions = function(name){
    return {name: name, addRootSlash: false, transform: function(path){
        return '<script src="'+ path.replace('app/', '')+'"></script>'
    }}};
//Order must not change to avoid injector errors as angular looks the files in this order while bootstrapping the app
return target.pipe(inject(gulp.src(['./app/**/*.module.js']), injectOptions('module.js')))
    //all parent level js files
    .pipe(inject(gulp.src(['./app/*.js', '!./app/app.module.js', '!./app/*.spec.js'], {read:false}), injectOptions('main app')))
    .pipe(inject(gulp.src(['./app/api/api.services.js'], {read:false}), injectOptions('api service')))
    //all js files under api folder except module/services
    .pipe(inject(gulp.src(['./app/api/*.js', '!./app/api/*.module.js', '!./app/api/*.services.js', '!./app/api/*.spec.js'], {read:false}),
        injectOptions('api')))
    .pipe(inject(gulp.src(['./app/utils/stringUtils.js'], {read:false}), injectOptions('stringutils')))
    //all files under utils except module/stringUtils
    .pipe(inject(gulp.src(['./app/utils/*.js', '!./app/utils/*.module.js', '!./app/utils/stringUtils.js', '!./app/utils/*.spec.js'], {read:false}),
        injectOptions('utils')))
    //all files under authentication except module
    .pipe(inject(gulp.src(['./app/authentication/*.js', '!./app/authentication/*.module.js', '!./app/authentication/*.spec.js'], {read:false}),
        injectOptions('authentication')))
    //all files under shared except module
    .pipe(inject(gulp.src(['./app/shared/*.js', '!./app/shared/*.module.js', '!./app/shared/*.spec.js'], {read:false}), injectOptions('shared')))
    //all directives which are named as directive/directives which are under components
    .pipe(inject(gulp.src(['./app/components/**/*.directive.js', './app/components/**/*.directives.js'], {read:false}),
        injectOptions('component directives')))
    //all services under components
    .pipe(inject(gulp.src(['./app/components/**/*.service.js'], {read:false}),
        injectOptions('component services')))
    //all other js files under components which are neither directive/directives nor services
    .pipe(inject(gulp.src(['./app/components/**/*.js',
        '!./app/components/**/*.service.js', '!./app/components/**/*.directive.js',
        '!./app/components/**/*.directives.js', '!./app/components/**/*.module.js', '!./app/components/**/*.spec.js'], {read:false}),
        injectOptions('other component files')))
    .pipe(gulp.dest('./app'));

});`

There seems to be some dependency updates which I have observed,

new
[INFO] ├─┬ gulp-inject@4.2.0
[INFO] │ ├── arrify@1.0.1
[INFO] │ ├── escape-string-regexp@1.0.5
[INFO] │ ├─┬ group-array@0.3.2
[INFO] │ │ ├── arr-flatten@1.0.1
[INFO] │ │ ├── get-value@2.0.6
[INFO] │ │ ├─┬ kind-of@3.1.0
[INFO] │ │ │ └── is-buffer@1.1.4
[INFO] │ │ └─┬ union-value@0.2.3
[INFO] │ │ ├── arr-union@3.1.0
[INFO] │ │ └─┬ set-value@0.3.3
[INFO] │ │ ├── extend-shallow@2.0.1
[INFO] │ │ └─┬ to-object-path@0.2.0
[INFO] │ │ └── is-arguments@1.0.2
[INFO] │ └─┬ stream-to-array@2.3.0
[INFO] │ └── any-promise@1.3.0

OLD which was working

[INFO] ├─┬ gulp-inject@4.2.0
[INFO] │ ├── arrify@1.0.1
[INFO] │ ├── escape-string-regexp@1.0.5
[INFO] │ ├─┬ group-array@0.3.1
[INFO] │ │ ├── get-value@2.0.6
[INFO] │ │ └─┬ kind-of@3.1.0
[INFO] │ │ └── is-buffer@1.1.4
[INFO] │ └─┬ stream-to-array@2.3.0
[INFO] │ └── any-promise@1.3.0

It worked after changing package.json from group-array : "^0.3.0" to group-array: "0.3.1".

Please try to fix the dependencies.

dimy4 commented

hi chaitanyavangoori,

i have a same problem.
I changed the package.json to:

{
"devDependencies": {
    "gulp": "^3.9.1",
    "group-array": "0.3.1",
    "gulp-inject": "^4.2.0"
  }
}

and now it works! But is this the only solution to use the option "starttag"?

Same here

I used npm-shrinkwrap to lock the dependencies. I also changed the versiob of group-array back to 0.3.1.

wish we had seen this issue sooner. we just now received an issue about this on group-array, looks like a regression that should be easy to fix. or if shrinkwrapping is easier we can leave it as is.

x1c0 commented

Same error here :(

I believe this was fixed by @doowb in group-array

gulp inject
[00:12:32] Using gulpfile ~\Documents\NodejsWorkshop\gulpfile.js
[00:12:32] Starting 'inject'...
(node:26112) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): [object Object]
(node:26112) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

var gulp = require('gulp');
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
var nodemon = require('gulp-nodemon');
var jsFiles = ['.js','src/**/.js'];
gulp.task('style',function(){
return gulp.src(jsFiles)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish',
{verbose : true}))
.pipe(jscs());

});

gulp.task('inject',function(){
var wiredep = require('wiredep').stream;
var inject = require('gulp-inject');

var injectSrc = gulp.src([',/public/css/.css',
'./public/js/
.js'],{read : false});
var injectOptions = {
ignorePath: '/public'
};
var options = {
bowerJson : require('./bower.json'),
directory : './public/lib'
};
return gulp.src('./src/views/*.html')
.pipe(wiredep(options))
.pipe(inject(injectSrc, injectOptions))
.pipe(gulp.dest('./src/views'));

});

please help!

Im having the same issue with gulp-inject ^4.3.1

//This is my method that breaks
gulp.src('./snippets/global/critical-css.html')
        .pipe(inject(gulp.src(['./styles/critical.css']), {
            starttag: '/* cssinject */',
            transform: function (filePath, file) {
            return file.contents.toString();
            }
        }))
        .pipe(gulp.dest('./dist'));

UPDATE: the html is critical-css.html

<style>
/* cssinject */
/* endinject */
</style>

Error is:

(node:10641) UnhandledPromiseRejectionWarning
(node:10641) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:10641) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Other env settings:

gulp ^3.9.1
npm 5.7.1
node v9.3.0
rejas commented

@juanpasolano can you paste your html with the inject tags also? thx in advance

@rejas thanks for getting back... I've updated my comment with the html i'm using.

rejas commented

Deleted my old comments to sumamrize my findings:
Using your code with gulp4 gave a better error message:

Message:
    Missing end tag for start tag: /* cssinject */
Details:
    domainEmitter: [object Object]
    domain: [object Object]
    domainThrown: false

looking at the src code of this plugin it cannot infer from your starttag how the endtag will look like so you have to a) either specify the endTag option with /* endinject */ or b) switch the endtag in the html to the default <!-- --> is that a possibility for you @juanpasolano ?