Error TS1056: Accessors are only available when configuring ECMAScript 5 in gulp - typescript

I came up with this error message by transcribing TS in JS using gulp - typescript. I am trying to use the ES5 function for getters / seters.

error TS1056: Accessors are available only when configuring ECMAScript 5 or higher

How to get a transcompiler for targeting on es5?

I googled for solutions that suggest setting target = es5 and passing it to typescript. I did the following using 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())); }); 

registered output

enter image description here

+6
source share
3 answers

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

+2
source

The gulp - typescript plugin has the "target" option. I found that setting up the tsconfig.json file has no effect, but when I changed the target to es5 in my gulp task, it worked fine.

plugin options

 ... .pipe(typescript(tsProject(), { target: 'ES5'})) ... 
+1
source

On Windows and Visual Studio, in the console window, enter the following command: tsc -target "es5" yourFilename.ts

-one
source

Source: https://habr.com/ru/post/1011901/


All Articles