Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject fails for version 4.2.0 #219

Open
chaitanyavangoori opened this issue Feb 28, 2017 · 12 comments
Open

Inject fails for version 4.2.0 #219

chaitanyavangoori opened this issue Feb 28, 2017 · 12 comments

Comments

@chaitanyavangoori
Copy link

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] ├─┬ [email protected]
[INFO] │ ├── [email protected]
[INFO] │ ├── [email protected]
[INFO] │ ├─┬ [email protected]
[INFO] │ │ ├── [email protected]
[INFO] │ │ ├── [email protected]
[INFO] │ │ ├─┬ [email protected]
[INFO] │ │ │ └── [email protected]
[INFO] │ │ └─┬ [email protected]
[INFO] │ │ ├── [email protected]
[INFO] │ │ └─┬ [email protected]
[INFO] │ │ ├── [email protected]
[INFO] │ │ └─┬ [email protected]
[INFO] │ │ └── [email protected]
[INFO] │ └─┬ [email protected]
[INFO] │ └── [email protected]

OLD which was working

[INFO] ├─┬ [email protected]
[INFO] │ ├── [email protected]
[INFO] │ ├── [email protected]
[INFO] │ ├─┬ [email protected]
[INFO] │ │ ├── [email protected]
[INFO] │ │ └─┬ [email protected]
[INFO] │ │ └── [email protected]
[INFO] │ └─┬ [email protected]
[INFO] │ └── [email protected]

@chaitanyavangoori
Copy link
Author

chaitanyavangoori commented Mar 1, 2017

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
Copy link

dimy4 commented Mar 7, 2017

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"?

@equinusocio
Copy link

Same here

@chaitanyavangoori
Copy link
Author

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

@jonschlinkert
Copy link

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
Copy link

x1c0 commented Apr 11, 2017

Same error here :(

@jonschlinkert
Copy link

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

@hedaukartik
Copy link

hedaukartik commented Mar 11, 2018

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!

@juanpasolano
Copy link

juanpasolano commented Mar 26, 2018

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
Copy link
Contributor

rejas commented Mar 27, 2018

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

@juanpasolano
Copy link

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

@rejas
Copy link
Contributor

rejas commented Mar 27, 2018

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants