A
A
Archakov Dennis2016-11-07 16:01:03
JavaScript
Archakov Dennis, 2016-11-07 16:01:03

Why is Gulp + Babelify not compiling correctly?

gulpfile.js:

const gulp = require('gulp');
const babel = require('gulp-babel');
const watch = require('gulp-watch');
const rename = require("gulp-rename");
const browserify = require('gulp-browserify');
const babelify = require("babelify");

gulp.task('js', () => {

  gulp.src('public/js/dev/app.js')
    .pipe(browserify({
      transform: ['babelify'],
    }))
    .pipe(gulp.dest('./public/js'))

});

gulp.task('watch:js', () => {
  gulp.watch(['public/js/dev/app.js','public/js/modules/*.js'], ['js']);
});

//...

app.js:
var Map = require('../modules/map.js');

var map = new Map('map',[43.2317986,44.749744]);

modules/map.js:
class Map
{

  constructor(id,arr) {
      this.map_id = id;
      this.latlong = arr;
      this.map = null;

      const tinyIcon = L.Icon.extend({
    		options: {
    			iconSize: [32, 32],
    			iconAnchor:   [12, 36],
    			popupAnchor: [0, -30]
    		}
    	});

      const me = new tinyIcon({ iconUrl: 'https://cdn3.iconfinder.com/data/icons/iconka-buddy-set/128/male_dummy_128.png' });
    	const guest = new tinyIcon({ iconUrl: 'https://cdn3.iconfinder.com/data/icons/iconka-buddy-set/128/ninja_128.png' });

      getLatLong => ( () => {
        console.log('asd');
      })
      // this.map = L.map(this.map_id).setView([latlong[0], latlong[1]], 12);
      //
      // L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png').addTo(this.map);
      //
      // const userMarker = L.marker([56.326944, 44.0075], {
  		// 	icon: redIcon
  		// });

  }

  setMarker(){
    return 0;
  }

  getLatLong(callback){
    navigator.geolocation.getCurrentPosition(position => {
      callback(position);
    });
  }

}

When I create an object of class Map . Displays this error in the console:
app.js:4 Uncaught TypeError: Map is not a constructor

Here's an example on a local server .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Damir Makhmutov, 2016-11-07
@archakov06

In modules/map.js do you have an export of the Map class?
or
module.exports = Map;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question