Grunt Typescript找不到角度核心 [英] Grunt Typescript can't find angular core
问题描述
p>我想这与路径有关,所以编译器无法在node_modules目录中找到库。
错误
typescript / add.component.ts(1,25):错误TS2307:无法找到模块'angular2 / core' 。
设置
Gruntfile.js任务
打字稿:{
all:{
src:['typescript / ** / *。ts'],
dest:'javascript / frontend',
options:{
target:es5,
module:system,
moduleResolution:node,
emitDecoratorMetadata:true,
experimentalDecorators:true,
removeComments:false,
noImplicitAny :false
}
}
打字稿/ add.component。 ts
import'Component'from'angular2 / core';
@Component({
selector:'mytest',
template:'< h1> test< / h1>'
})
导出class AppComponent {}
node_modules
- 包含angular2
- 包含打字稿
文件路径
app - node_modules
- 打字稿
- app.component.ts
- Gruntfile.js
- package.json
已使用的库/ frameworks / tutorials
刚才我有同样的问题。在详细模式下运行grunt显示了它从grunt配置生成的ts配置文件的内容。仔细看,这表明moduleResolution选项根本没有使用。但是,另一方面,它没有在官方的grunt-typecript页面上描述。
无论如何,长话短说:我已经使用 grunt-ts 包,取而代之的是一切正常!为了您的方便,我在下面发布了我的配置: - ) 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(咕噜-TS’); grunt.registerTask('default',['ts']);};
Question
Why cant my Grunt Typescript compiler find the angular core?
I guess it has something to do with the paths so the compiler cant find the libs in the node_modules directory.
Error
typescript/add.component.ts(1,25): error TS2307: Cannot find module 'angular2/core'.
Setup
Gruntfile.js Task
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
import {Component} from 'angular2/core';
@Component({
selector: 'mytest',
template: '<h1>test</h1>'
})
export class AppComponent { }
node_modules
- Includes angular2
- Includes typescript
Filepaths
app -- node_modules
-- typescript
-- app.component.ts
-- Gruntfile.js
-- package.json
Used libs/frameworks/tutorials
- Grunt Typescript Github
- Angular2 5min Quickstart
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. Looking more closely, this revealed that the moduleResolution option isn't used at all. But, on the other hand, it wasn't described either on the official grunt-typescript page.
Anyway, long story short: I've used the grunt-ts package instead and everything worked out well! 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']);
};
这篇关于Grunt Typescript找不到角度核心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!