1

I'm using [gulp-traceur][1] to compile es6 to js in my angularjs application (1.x). When I try and compile a for loop, I get the error:

ReferenceError: $traceurRuntime is not defined

It looks like I need to inject $traceurRuntime into my controller or something. Can anyone help me out?

Rimian
  • 36,864
  • 16
  • 117
  • 117

1 Answers1

6

$traceurRuntime is an object in the global scope, not an Angular injectable. This object comes from including the traceur runtime script file (traceur-runtime.js) in your app. Make sure you include the traceur.RUNTIME_PATH so the gulp task knows where to find it during compilation and includes it.

Assuming your gulpfile looks something like this:

// gulpfile.js
var traceur = require('gulp-traceur');

// ...

gulp.task('build', function() {
  return gulp.src([
    traceur.RUNTIME_PATH, // <-- add this
    'src/**/*.*'
  ])
  .pipe(traceur({ /* traceur config */ })
  .pipe(gulp.dest('/dist'));
});
user2943490
  • 6,900
  • 2
  • 22
  • 38
  • Thanks! Do you know how I can find out the runtime path? Is it where traceur lives? For me this is: /usr/local/bin/traceur – Rimian Dec 19 '14 at 00:44
  • @Rimian Phrasing was a bit off. You should set the runtime path as an entry for gulp.src, so that it's pulled in. Updated the answer. – user2943490 Dec 19 '14 at 01:41