I am trying to setup Grunt build task for my Angular 4 project and seeing some module load errors when I try to run the tasks. Details of the steps I've done are -
1. Went to https://angular.io/guide/quickstart and used the steps mentioned in quickstart to create a new Angular4 app. Tested and ensured it is working.
2. Updated package.json file to include the following:
"grunt": "~0.4.5",
"grunt-typescript": "^0.8.0",
"grunt-contrib-copy": "~1.0.0",
Added Gruntfile.js with following content:
module.exports = function(grunt) {
grunt.initConfig({
typescript: {
base: {
src: [
'src/app//.ts',
],
dest: 'out/static/app.js',
options: {
target: 'es5',
sourceMap: false,
moduleResolution: 'node'
}
}
}
});
grunt.loadNpmTasks('grunt-typescript');
//grunt.loadNpmTasks('grunt-contrib-copy');
grunt.registerTask("default", ["typescript"]);
grunt.registerTask("build", ["typescript"]);
};Run
grunt build
.
When I run grunt build
, I get the following in terminal:
Running "typescript:base" (typescript) task
>> src/app/app.component.spec.ts(1,32): error TS2307: Cannot find module '@angular/core/testing'.
>> src/app/app.component.spec.ts(5,1): error TS2304: Cannot find name 'describe'.
>> src/app/app.component.spec.ts(6,3): error TS2304: Cannot find name 'beforeEach'.
>> src/app/app.component.spec.ts(14,3): error TS2304: Cannot find name 'it'.
>> src/app/app.component.spec.ts(17,5): error TS2304: Cannot find name 'expect'.
>> src/app/app.component.spec.ts(20,3): error TS2304: Cannot find name 'it'.
>> src/app/app.component.spec.ts(23,5): error TS2304: Cannot find name 'expect'.
>> src/app/app.component.spec.ts(26,3): error TS2304: Cannot find name 'it'.
>> src/app/app.component.spec.ts(30,5): error TS2304: Cannot find name 'expect'.
>> src/app/app.component.ts(1,1): error TS1148: Cannot compile modules unless the '--module' flag is provided.
>> src/app/app.component.ts(1,27): error TS2307: Cannot find module '@angular/core'.
>> src/app/app.component.ts(8,14): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning.
>> src/app/app.module.ts(1,31): error TS2307: Cannot find module '@angular/platform-browser'.
>> src/app/app.module.ts(2,26): error TS2307: Cannot find module '@angular/core'.
>> src/app/app.module.ts(16,14): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning.
Warning: Task "typescript:base" failed. Use --force to continue.
It seems other user has faced similar issue, but had to switch to grunt-ts
instead of using grunt-typescript
. Does anybody have suggestions on how to get this working?
Though we have angular-cli (ng build) to build Angular 4 code, the reason I am trying this is because I am going to use this in a project which has Python backend code and is grunt build tasks. I would like to merge all my build tasks to existing Gruntfile.js. I am newbie to Angular4 and Typescript. Learning as I work more on them and struggling to get this issue resolved.