我正在尝试为我的Angular 4项目设置Grunt构建任务,并在尝试运行任务时看到一些模块加载错误。我所做的步骤的细节是 -
1.去https://angular.io/guide/quickstart并使用quickstart中提到的步骤创建一个新的Angular4应用程序。经过测试并确保其正常工作
2.更新了package.json文件以包含以下内容:
"grunt": "~0.4.5",
"grunt-typescript": "^0.8.0",
"grunt-contrib-copy": "~1.0.0",
添加了以下内容的Gruntfile.js:
module.exports = function(grunt){
grunt.initConfig({
打字稿:{
基地:{
src:[
'SRC /应用/的 / .TS',
],
dest:'out / static / app.js',
选项:{
目标:'es5',
sourceMap:false,
moduleResolution:'node'
}
}
}
});
grunt.loadNpmTasks( '咕噜-打字稿');
//grunt.loadNpmTasks('grunt-contrib-copy');
grunt.registerTask(“default”,[“typescript”]);
grunt.registerTask(“build”,[“typescript”]);
};
运行grunt build
。
当我运行grunt build
时,我在终端中获得以下内容:
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.
其他用户似乎遇到了类似的问题,但不得不切换到grunt-ts
而不是grunt-typescript
。有没有人建议如何使这个工作?
虽然我们有angular-cli(ng build)来构建Angular 4代码,但我之所以这样做是因为我将在一个拥有Python后端代码并且是grunt构建任务的项目中使用它。我想将所有构建任务合并到现有的Gruntfile.js。我是Angular4和Typescript的新手。学习,因为我更多地研究它们并努力解决这个问题。
答案 0 :(得分:0)