Reading some docs about gulp.js and how tasks work, I found myself asolution and it is quite simple. In gulpfile.js, there is a variable that needs the ionic-gulp-browserify-typescript library. This library uses Browserify to transpile and bundle the TypeScript source files.:
var buildBrowserify = require('ionic-gulp-browserify-typescript');
As you can see in the npm API doc of the library, there is an option (src) which says:
- src (string|File|Array) String, file object, or array of those types (they may be mixed) specifying Browserify entry file(s). Default: [‘./app/app.ts’, ‘./typings/main.d.ts’].
When you install the typescript definitions for the library via typings install amqplib --save
, it sometimes creates its own index.d.ts file inside typings directory, so the gulp builder and Browserify will ignore it:
###Posible solutions:
- The first one: Add index.d.ts to the library src field (not recommended):
Everything you have to do is adding the index.d.ts file to the src field at node_modules > ionic-gulp-browserify-typescript > index.js, like this:
src: ['./app/app.ts', './typings/main.d.ts', './typings/index.d.ts'],
I would say it is not recommended because you are changing code in the library itself, and it is never a good idea if you don’t know exactly how it works.
- The second one: Add the references to main.d.ts:
You only need to copy the content from index.d.ts…
/// <reference path="globals/amqplib/index.d.ts" />
/// <reference path="globals/node/index.d.ts" />
/// <reference path="globals/when/index.d.ts" />
… and add it to main.d.ts. Once it is done, the gulp builder will understand where amqplib typescript defiinition is located and you will get no error messages from build task.