When using gulp-typescript to compile my TypeScript files, the issue arises where external modules such as "@angular/core" are not found. How can I configure TSC to search for these modules in the node_modules folder?
Additionally, I would like to bundle the TypeScript files with systemJS. Is there a way to include the systemjs-config so that TSC knows where to look?
CODE:
gulp.task('tsc:release_dist', function() {
return gulp.src(releaseBuildDest+'/**/*.ts')
.pipe(gulpIgnore('node_modules/**'))
.pipe(debug())
.pipe(tsc({
noImplicitAny: true,
out: 'bundle.js',
module: 'system'
}))
.pipe(gulp.dest(releaseBuildDest));
});
My project structure:
.dist/
..../release/
......./app/ (Angular2 components, ...)
......./assets/ (CSS, img, ...)
......./node_modules/ (Angular2 and other dependencies)
.......index.html
.......main.ts
.......systemjs.config.js
Console output:
[12:25:59] Using gulpfile C:\Develop\frontend\gulpfile.js
[12:25:59] Starting 'tsc:release_dist'...
[12:26:00] gulp-debug: dist\release\main.ts
[12:26:03] gulp-debug: dist\release\app\app.component.spec.ts
[12:26:05] gulp-debug: dist\release\app\app.component.ts
[12:26:05] gulp-debug: dist\release\app\app.module.ts
[12:26:05] gulp-debug: dist\release\app\components\afafc\authafafc\authafafc.component.ts
[12:26:05] gulp-debug: dist\release\app\components\afafc\langafafc\langafafc.component.ts
[12:26:06] gulp-debug: 6 items
dist\release\app\app.component.spec.ts(3,50): error TS2307: Cannot find module '@angular/core/testing'.
dist\release\app\app.component.spec.ts(4,20): error TS2307: Cannot find module '@angular/platform-browser'.
dist\release\app\app.component.spec.ts(5,30): error TS2307: Cannot find module '@angular/core'.
dist\release\app\app.component.ts(1,27): error TS2307: Cannot find module '@angular/core'.
dist\release\app\app.module.ts(2,31): error TS2307: Cannot find module '@angular/platform-browser'.
dist\release\app\components\afafc\authafafc\authafafc.component.ts(1,34): error TS2307: Cannot find module '@angular/core'.
dist\release\app\components\afafc\langafafc\langafafc.component.ts(1,34): error TS2307: Cannot find module '@angular/core'.
dist\release\main.ts(1,40): error TS2307: Cannot find module '@angular/platform-browser-dynamic'.
How my components are requiring these packages:
import { NgModule } from '@angular/core';
tsconfig.js
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}
Additional information: Everything works fine when I compile the regular dev build using "npm start", which is a shortcut to tsc -p src/. However, I'm encountering errors when trying to build a "release build" gulp-task with bundled files. When I copy everything to my release build directory and try to compile with tsc, the errors mentioned above occur.
package.json
{
"name": "my-project",
"version": "1.0.0",
"description": "my-project",
... (remaining content unchanged)
}