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
What I did is compile the ts file with this "tsc --target ES5 YourFile.ts"
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'}))
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With