Rhushikesh
Rhushikesh

Reputation: 3700

Gulp is not generate js file from ts

here is my Gulp task:

var gulp = require('gulp');
var typescript = require('gulp-typescript');
var sourcemaps = require('gulp-sourcemaps');
var tsProject = typescript.createProject('tsconfig.json');
var tsSources = [
    './typings/**/*.ts',
    'server/**/*.ts'
];

module.exports = function () {
    var tsResult = gulp.src(tsSources)
        .pipe(sourcemaps.init())
        .pipe(typescript(tsProject));

    return tsResult.js
        .pipe(sourcemaps.write())
        .pipe(gulp.dest('server/'));
};

here is my tsconfig

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "sourceMap": true,
        "watch": true,
        "removeComments": true,
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "declaration": false,
        "noImplicitAny": false,
        "noLib": false
    },
    "exclude": [
        "fonts",
        "images",
        "img",
        "libs",
        "navigation",
        "node_modules",
        "pagehtmls",
        "typings"
    ]
}

here is my ts file:

/// <reference path="../typings/_all.d.ts" />
'use strict';
import {Request, Response} from 'express';
var config = require('../../config/environment'),
    auth = require('../../auth/auth.service');
var mongodb = require('mongodb');
var MongoClient = mongodb.MongoClient;


exports.getBooking = (req: Request, res: Response) => {
    MongoClient.connect(config.mongoERP.uri, (err, db) => {
        if (err) { return res.send(err); }
        db.getCollection('customers').find({ email1: req.params.email }).toArray((err, customer) => {
            if (err) { return res.send(err); }
            return res.send(customer);
        });
    });
}

here is my tsd.json

{
  "version": "v4",
  "repo": "borisyankov/DefinitelyTyped",
  "ref": "master",
  "path": "typings",
  "bundle": "typings/_all.d.ts",
  "installed": {
    "angularjs/angular.d.ts": {
      "commit": "2d4c4679bc2b509f27435a4f9da5e2de11258571"
    },
    "angular-ui-router/angular-ui-router.d.ts": {
      "commit": "c50b111ded0a3a18b87b5abffea3150d6aca94da"
    },
    "jquery/jquery.d.ts": {
      "commit": "2d4c4679bc2b509f27435a4f9da5e2de11258571"
    },
    "lodash/lodash.d.ts": {
      "commit": "2d4c4679bc2b509f27435a4f9da5e2de11258571"
    },
    "node/node.d.ts": {
      "commit": "2d4c4679bc2b509f27435a4f9da5e2de11258571"
    },
    "socket.io-client/socket.io-client.d.ts": {
      "commit": "2d4c4679bc2b509f27435a4f9da5e2de11258571"
    },
    "serve-static/serve-static.d.ts": {
      "commit": "b57c33fec0be3cba8f5e9cec642db873565923d0"
    },
    "mime/mime.d.ts": {
      "commit": "b57c33fec0be3cba8f5e9cec642db873565923d0"
    },
    "express/express.d.ts": {
      "commit": "470954c4f427e0805a2d633636a7c6aa7170def8"
    },
    "es6-shim/es6-shim.d.ts": {
      "commit": "dade4414712ce84e3c63393f1aae407e9e7e6af7"
    },
    "mongoose/mongoose.d.ts": {
      "commit": "6766ed1d0faf02ede9e2edf2e66bbb2388c825ec"
    }
  }
}

I am using gulp cli version 3.9.0 and local 3.9.1 its gives the error error TS1128: Declaration or statement expected for the import If i remove './typings/**/*.ts', from gulp task and

path="../../server.d.ts" />
import {Request, Response} from 'express';

from my ts file its work fine but give diff error messages while compilation. I have lot of ts file so i cant remove it.

Upvotes: 0

Views: 406

Answers (2)

Arun Tyagi
Arun Tyagi

Reputation: 2256

I faced the the Problem..

Just update your Gulp Typescript.

This worked for me.

Upvotes: 0

Amid
Amid

Reputation: 22352

You should not exclude all typings folder in your tsconfig as it contains definitions for the compiler, including the ones of express. Most likely you want to only exclude typings\browser for example.

Also I can recommend to use tsProject.src() instead of gulp.src so that structure of your projects is defined only in one place - tsconfig.

Hope this helps.

Upvotes: 1

Related Questions