Good afternoon, help figure out, I can not properly build a project.

I constantly work with NodeJS and here I also had to put angular.

I collect everything through Gulp.

Gulp task:

gulp.task('js', function () { return gulp.src(source()) .pipe(browserify({ insertGlobals: true })) .pipe(concat('bundle.js')) .pipe(uglify()) .pipe(rename({ suffix: '.min' })) .pipe(gulp.dest('./public/build/')); }); 

Source:

 function returnSource(){ var files = [ './public/js/*.js', './public/js/controller/*.js', './public/js/router/*.js', ]; return files; } module.exports.returnSource = returnSource; 

JS folder structure

 JS controller index.js router template view app.js 

The structure of the app.js file

 require('angular'); var app = angular.module('photography', []); 

Structure of the /controller/index.js file

 app.controller("index", function($scope) { $scope.products = [""]; }); 

Angular installed via npm

I get the output file bundle.min.js

It gives an error when loading the page that Cannot find module (And this is from the require side)

Do not understand why. According to my logic, if I did require ('angular'), then angular.js should be moved from the node_modules folder to the app.js file, and in the end, for some reason, the require functions are also involved.

How to do it right?

Picture with an error

  • try not to minify and see what really swears - Grundy

1 answer 1

So. The fact that you build through gulp does not mean that JS will then understand your require function

 angular.module('app', []) 

this is already the client's side ( NOT NODE.JS ) and there is no need to know require('angular') :) you will need to connect the standard angular via

 <script src="path/to/your/angular.js"></script> 

remove the line with require from .js

Good coding :)

  • Well, in fact, gulp collects the project and pulls Angular out of the module nodes folder and inserts it into the file, and angular itself is already in the bundle.min.js file. Why there also require dragging on? I just want me to have everything in one file and my code and the angular library itself. I can make changes in gulp and collect the file, taking into account that he would go into the node modules and take it from there. But I thought it was realizable through require - Vladimir Vyacheslavovich
  • Apparently some module assumes that you use the require method to include the requireJs module. Therefore, you will have to include this file as well ... but IMHO is an extra load on the page. angular and so good at modularity - Pleshevskiy
  • It's all strange) - Vladimir Vyacheslavovich
  • actually everything is clear. frontender.info/gulp-browserify-starter-faq browserify turns wraps into requireJS. By the way, you can just concatenate a single angular file and not have to suffer with requireJS. With him, I'm not your assistant :) - Pleshevskiy
  • it turns out it is looking for the file angular.js in your root folder next to app.js and with all the other js too. Naturally, he cannot find him, because it is generally outside the static domain. in node_modules - Pleshevskiy