Currently, I am in the process of developing a web application utilizing angular version 1.5 along with typescript 2.4.0. Additionally, I am integrating moment version 2.18.1 and gulp for handling project assembly.
Here is an excerpt from my tsconfig.json
file:
{
"files": [
"src/app/main.ts",
"types/**/*.ts"
],
"compilerOptions": {
"noImplicitAny": false,
"target": "es2015",
"allowSyntheticDefaultImports": true
}
}
Within my date-range-picker.component.ts
, I am importing the moment library as recommended in the primary documentation available at here:
import * as moment from 'moment';
This setup works seamlessly with the main project assembly task in gulp that relies on the tsify plugin:
var browserifyIt = browserify({
basedir: '.',
debug: true,
entries: paths.browserifyEntries,
cache: {},
packageCache: {}
}).plugin(tsify);
gulp.task('bundle', ['views'], function () {
return browserifyIt
.transform('babelify', {
presets: ['es2015'],
extensions: ['.ts']
})
.bundle()
.on('error', interceptErrors)
.pipe(source(fileNames.buildJs))
.pipe(ngAnnotate())
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write(paths.sourcemapPath))
.pipe(gulp.dest(paths.build));
});
However, when it comes to compiling tests, I have decided to utilize a task that employs tsProject():
const testSrcPaths = {
....,
componentTests: 'src/app/components/**/*.test.ts',
....
};
gulp.task('component-tests:compile', function () {
return gulp.src(testSrcPaths.componentTests).pipe(tsProject())
.on('error', interceptErrors)
.js.pipe(gulp.dest(`${paths.testsDist}/components`));
});
This approach has resulted in the following error message:
date-range-picker/date-range-picker.component.ts(2,25): error TS2307: Cannot find module 'moment'.
How can I go about resolving this issue?