首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular2β和gulp找不到模块'angular2/core‘

Angular2β和gulp找不到模块'angular2/core‘
EN

Stack Overflow用户
提问于 2016-03-01 15:42:44
回答 1查看 1.2K关注 0票数 1

我正在尝试自动化的类型记录编译与新的角2.0测试版。

项目结构是:

代码语言:javascript
复制
myapp
|--node_modules
     |---angular2
            |--core.d.ts
            |--...
|--lib
    |--resources
         |--app
             |--app.component.ts
|--typings
     |--..
.
|--package.json
|--gulpfile.js

app.component.ts节选:

代码语言:javascript
复制
import {Component, View} from 'angular2/core';
import {TechnologiesService} from './services';

当我直接从shell运行typescript命令(tsc)时,一切都进行得很好,并且生成了javascript文件。但是,当我运行gulp编译任务时,会出现一些错误,因为它没有找到angular2 2/core和angular2 2/platform/browser模块。为什么?

代码语言:javascript
复制
[16:35:55] Using gulpfile C:\dev\myapp\gulpfile.js
[16:35:55] Starting 'compile-ts'...
[16:35:55] Compiling TypeScript files using tsc version 1.8.2
[16:35:56] [tsc] > lib/resources/app/app.component.ts(1,46): error TS2307: Cannot find module 'angular2/core'.
[16:35:56] [tsc] > lib/resources/app/app.component.ts(44,14): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
[16:35:56] [tsc] > lib/resources/app/main.ts(1,28): error TS2307: Cannot find module 'angular2/platform/browser'.
[16:35:56] Failed to compile TypeScript: Error: tsc command has exited with code:2

events.js:154
      throw er; // Unhandled 'error' event
      ^
 Error: Failed to compile: tsc command has exited with code:2

gulpfile 类型记录编译任务

代码语言:javascript
复制
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var typescript = require('gulp-tsc');
gulp.task('compile-ts', function(){
  return gulp.src(['./lib/resources/app/**/*.ts'])
    .pipe(typescript({"target": "es5", "module": "system", "moduleResolution": "node", "sourceMap": true,
                      "experimentalDecorators": true, "emitDecoraasdftorMetadata": true, "removeComments": false,
                      "noImplicitAny": false}))
    .pipe(gulp.dest('./public/app/'));
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-23 22:53:38

我使用的是一体式文本,而不是gulp,下面的gulpfile.js非常适合指定的tsconfig.json文件。

代码语言:javascript
复制
var gulp = require('gulp');
var ts = require('gulp-typescript');
var path = require('path');
var sourcemaps = require('gulp-sourcemaps');

gulp.task('build:client', function () {
    var tsProject = ts.createProject('client/tsconfig.json');
    var tsResult = gulp.src([
        'client/**/*.ts',
        '!client/typings/main/**/*.ts',
        '!client/typings/main.d.ts'
    ])        
        .pipe(sourcemaps.init())
        .pipe(ts(tsProject))
    return tsResult.js
        .pipe(sourcemaps.write())
        .pipe(gulp.dest('server'))
});

gulp.task('default', ['build:client']);

我的tsconfig.json

代码语言:javascript
复制
{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "rootDir":"./"    
  },
  "exclude": [    
    "typings/main",
    "typings/main.d.ts"
  ]
}

安装台风

代码语言:javascript
复制
npm install typings --save-dev

初始化typings.json

代码语言:javascript
复制
typings init

安装“ES6-集合”和“ES6-承诺”的类型

代码语言:javascript
复制
typings install es6-collections --ambient --save
typings install es6-promise --ambient --save
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35727170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档