Search code examples
javascriptangularjsgulpbundling-and-minificationangularjs-injector

bundling and minification causes angular error: $injector:unpr unknown provider


I'm working on a large project, where minification of java and css was used before with Web Essentials, but no bundling has been yet made.

I want to move away from WebEssentials now and use something else.

I'v started with minification and bundling just a part of app .js files using Gulp, but when loading the project got an error from one of the pages:

Error: $injector:unpr Unknown Provider caused by other .min.js files,

which all worked fine before I've added mine.

All files are added to the path exactly in the same order, as they should be loaded on the page. Also replaced just those files which have been added to the bundle.

gulp code for minification:

gulp.task("min:appjs", function ()
{
    return gulp.src(["!gulpfile.js", "!app/" + paths.minJs, paths.appjs], { base: "." })
        .pipe(sourcemaps.init())
            .pipe(concat(paths.concatJsAppDest), { newLine: ';' })
            .pipe(ngmin())
            .pipe(annotate())
            .pipe(uglify())
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest('.'));
});

What I can't wrap my mind about: how my minified file causes others minified files to crush when they've worked before. Plus one page of the project loads without any errors and others don't work.

Any ideas where I should check?


Solution

  • Ok, so the way I had to handle this was checking which file caused the error. It appeared so one of the .js.min files from further if statements in the code was referring to the file in the bundle and couldn't find the reference.

    Taking that file out of the bundle and keeping it separately solved the problem.

    If there are any ideas how to include it in the bundle and still keep the reference, I would be glad to try it out.