[英]Grunt Typescript can't find angular core
Question 题
Why cant my Grunt Typescript compiler find the angular core? 为什么我的Grunt Typescript编译器找不到角度核心?
I guess it has something to do with the paths so the compiler cant find the libs in the node_modules directory. 我想它与路径有关,所以编译器无法在node_modules目录中找到libs。
Error 错误
typescript/add.component.ts(1,25): error TS2307: Cannot find module 'angular2/core'.
typescript / add.component.ts(1,25):错误TS2307:找不到模块'angular2 / core'。
Setup 建立
Gruntfile.js Task Gruntfile.js任务
typescript: {
all: {
src: ['typescript/**/*.ts'],
dest: 'javascript/frontend',
options: {
target: "es5",
module: "system",
moduleResolution: "node",
emitDecoratorMetadata: true,
experimentalDecorators: true,
removeComments: false,
noImplicitAny: false
}
}
typescript/add.component.ts 打字稿/ add.component.ts
import {Component} from 'angular2/core';
@Component({
selector: 'mytest',
template: '<h1>test</h1>'
})
export class AppComponent { }
node_modules node_modules
Filepaths 文件路径
app -- node_modules
-- typescript
-- app.component.ts
-- Gruntfile.js
-- package.json
Used libs/frameworks/tutorials 使用过的libs / frameworks / tutorials
Just now I had the same exact problem. 刚才我遇到了同样的问题。 Running grunt in verbose mode showed the content of the ts config file it generated from the grunt config.
以详细模式运行grunt显示了它从grunt配置生成的ts配置文件的内容。 Looking more closely, this revealed that the moduleResolution option isn't used at all.
仔细观察,结果表明,根本没有使用moduleResolution选项。 But, on the other hand, it wasn't described either on the official grunt-typescript page.
但是,另一方面,它没有在官方的grunt-typescript页面上描述。
Anyway, long story short: I've used the grunt-ts package instead and everything worked out well! 无论如何,长话短说:我已经使用了grunt-ts包而且一切顺利! I've posted my config below for your convenience :-)
为方便起见,我在下面发布了我的配置:-)
module.exports = function(grunt) { grunt.initConfig({ ts: { base: { src: ['src/**/*.ts'], dest: 'dist', options: { module: 'system', moduleResolution: 'node', target: 'es5', experimentalDecorators: true, emitDecoratorMetadata: true, noImplicitAny: false } } } }); grunt.loadNpmTasks('grunt-ts'); grunt.registerTask('default', ['ts']); };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.