ivogabe / gulp-typescript

A TypeScript compiler for gulp with incremental compilation support.
MIT License
839 stars 129 forks source link

[Question] How to setting gulp-typescript options to obtain es5 code #602

Closed romelgomez closed 5 years ago

romelgomez commented 5 years ago

I'm building a base express.js project with angular, and I have a server directory with a bunch of typescript files, that are processed with gulp-typescript, the thing is that seems the compilation process is run fine, but then I run a development server I getting this error:

/home/romel/Desktop/ng-express-base/dist/server/development.js:2
import * as __server from './app';
       ^

SyntaxError: Unexpected token *
    at new Script (vm.js:80:7)
    at createScript (vm.js:264:10)
    at Object.runInThisContext (vm.js:316:10)
    at Module._compile (internal/modules/cjs/loader.js:670:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)
    at Module.load (internal/modules/cjs/loader.js:605:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:544:12)
    at Function.Module._load (internal/modules/cjs/loader.js:536:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)
    at startup (internal/bootstrap/node.js:303:19)   

Expected behavior: import replaced by 'require'
Actual behavior: import's are keep in the compiled javascript files.

Your gulpfile: https://github.com/romelgomez/ng-express-base/blob/master/gulpfile.js

tsconfig.json https://github.com/romelgomez/ng-express-base/blob/master/tsconfig.json

Code Compiled: https://github.com/romelgomez/ng-express-base/tree/master/dist/server Sources: https://github.com/romelgomez/ng-express-base/tree/master/src/server

romelgomez commented 5 years ago

I fixed, set commonjs in module options

module?: string; //'amd'|'commonjs' (default)