简体   繁体   English

Grunt Typescript无法找到角度核心

[英]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

  • Includes angular2 包括angular2
  • Includes typescript 包括打字稿

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.

相关问题 Angular Grunt构建在分发构建期间找不到uglifyjs模块 - Angular grunt build can't find uglifyjs module during distribution build Visual Studio 2013找不到用于angular 2项目的Typescript版本 - Visual Studio 2013 can't find version of Typescript for angular 2 project Sailjs + Angularjs + Yeoman + Grunt无法启动角度服务器 - Sailjs + Angularjs + Yeoman + Grunt can't start angular server 带有angular2和咕unt声错误的打字稿TS2304:找不到名称 - Typescript with angular2 and grunt error TS2304: Cannot find name 使用Jasmine和Chutzpah在Visual Studio中测试TypeScript和AngularJS-找不到变量:angular - Testing TypeScript and AngularJS in Visual Studio with Jasmine and Chutzpah - can't find variable: angular .NET Core 2.0 和 Angular 初始应用程序构建失败 - 找不到 python,后面跟着 JavaScript 运行时错误 - .NET Core 2.0 & Angular Initial app build fails - Can't find python followed by JavaScript Runtime Error Angular mock找不到我的控制器,不能用Karma和require下的grunt运行js单元测试 - Angular mock can not find my controller, can not run js unit test with Karma and Requirejs under grunt unt角项目,然后由于找不到模块而出错 - grunt an angular project then it errors as Cannot find Module 对于Angular的Yeoman,然后“咕噜咕噜的服务”将无法启动 - Yeoman for Angular, then “grunt serve” won't start 打字稿tsc错误TS2307:找不到模块&#39;@ angular / core&#39; - typescript tsc error TS2307: Cannot find module '@angular/core'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM