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

4

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

Daman answered 31/10, 2016 at 22:56 Comment(1)
What is your question?Scriabin
R
5

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

Rather answered 17/12, 2016 at 1:39 Comment(2)
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.Labarbera
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.Oakleil
O
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'}))
...
Oakleil answered 22/12, 2016 at 17:33 Comment(0)
F
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
Fremont answered 20/4, 2018 at 13:30 Comment(0)
C
-1

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

Coelenteron answered 17/8, 2017 at 9:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.