Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error TS1056: Accessors are only available when targeting ECMAScript 5 in gulp-typescript

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

like image 858
David Cruwys Avatar asked Oct 31 '16 22:10

David Cruwys


2 Answers

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

like image 161
Rapirap LeeYo Avatar answered Oct 20 '22 03:10

Rapirap LeeYo


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'}))
...
like image 2
loctrice Avatar answered Oct 20 '22 03:10

loctrice