The browser does not work if you want to emphasize

I am using a browser for my angular client application. I need to use underscore. angular is installed with a gazebo and underscore is set with npm number

This is how I launch the browser (npm) and create the source map in gulp (npm)

gulp.task('browserify', function() { return browserify(dir.script_from + '/main.js', {debug: true}) .bundle() .pipe(source('bundle.js')) // gives streaming vinyl file object .pipe(buffer()) // <----- convert from streaming to buffered vinyl file object .pipe(sourcemaps.init({loadMaps: true})) .pipe(uglify()) // now gulp-uglify works .pipe(sourcemaps.write('./')) .pipe(gulp.dest(dir.script_to)); }); 

In my main.js I have

 //require('underscore') require('angular') require('angular-resource') require('angular-route') require('./home/home_page.js') ... 

if I do not require ('underscore'), the source map works. I can view the source files and set breakpoints.

enter image description here

But if I require ('underscore'), the source map no longer works. I can’t even browse files.

enter image description here

I also tried to set the underline using bower, but I get the following error:

 [23:59:02] Starting 'browserify'... events.js:85 throw er; // Unhandled 'error' event ^ Error: Cannot find module 'underscore' from '/Users/[my path]/app/client/script' 

Note that both bower (I config'ed the path) and npm put the modules in the folder "/ Users / [my path] / node_modules"

I even tried main.js with only one line: require('underscore') and did not work, but the empty main.js file works

+8
angularjs browserify
source share
2 answers

I have the same problem with underscore/browserify . Perhaps the best way is to exclude it from the kit. Just add the <script> to your underscore file. And in the bundle, you can directly use _ .

If you are using angular, it is recommended that you use a separate <script> , as most users probably already have angular available from the CDN for another angular website.

+1
source share

gulp checks for underscores in the root directory. Try adding underscore path in config.js or in package.json

config.js

 require: ['node_modules/underscore'] 

or

package.json

 "underscore": "./node_modules/underscore" 
+3
source share

All Articles