11

I'm coming up with an this error message while transcompiling TS to JS using gulp-typescript. I'm attempting to use an ES5 feature for getters/setters.

error TS1056: Accessors are only available when targeting ECMAScript 5 and higher

How do I get the transcompiler to target es5?

I googled around for solutions which suggest that you set target = es5 and pass it through to the typescript. I have done the following using a tsconfig.json

tsconfig.js

{
  "compilerOptions": {
    "target": "es5"
  },
  "files": []
}

gulp task

import gulp from 'gulp';
import gulpif from 'gulp-if';
import livereload from 'gulp-livereload';
import typescript from 'gulp-typescript';
import args from './lib/args';

const tsProject = typescript.createProject('tsconfig.json');

console.log(tsProject);

gulp.task('scripts-typescript', () => {
    return gulp.src('app/scripts/**/*.ts')
        .pipe(typescript(tsProject()))
        .pipe(gulp.dest(`dist/${args.vendor}/scripts`))
        .pipe(gulpif(args.watch, livereload()));
});

logged output

enter image description here

David Cruwys
  • 6,262
  • 12
  • 45
  • 91

4 Answers4

5

What I did is compile the ts file with this "tsc --target ES5 YourFile.ts"

Rapirap LeeYo
  • 55
  • 1
  • 9
  • 1
    Please don't go reposting the same answer on multiple questions. If the questions are the same, flag them as duplicate. (Requires almost no rep, easily earned.) If the questions are different, please tailor your answer to the question. – Baum mit Augen Dec 17 '16 at 01:41
  • 1
    this isn't really relevant. The suggestion you're using is the same as using the tsconfig if you're going to run the typescript compiler. But, the OP is using gulp, your answer has nothing to do with gulp or the tsconfig. – loctrice Jan 10 '17 at 17:03
3

the gulp-typescript plugin has an option called "target" . I found that setting up a tsconfig.json file didn't have any effect, but when I changed the target to es5 in my gulp task it worked fine.

plugin options

...
    .pipe(typescript(tsProject(), { target: 'ES5'}))
...
loctrice
  • 2,454
  • 1
  • 23
  • 34
0

try this

  • Go to terminal/cmd and navigate to the directory where your ts file exist.
  • Use following command. tsc filename.ts --target ES5
-1

In windows Operating System and Visual Studio code in console window type the following command: tsc -target "es5" yourFilename.ts