【问题标题】:gulp elixir-typescript failed to compilegulp elixir-typescript 无法编译
【发布时间】:2016-12-18 06:15:45
【问题描述】:

我正在尝试将 Angular2 与 laravel 5.2 一起使用,因此我正在尝试配置 gulp 来编译 typescript 文件。

这是我的 package.json 文件:

{
  "private": true,
  "scripts": {
    "prod": "gulp --production",
    "dev": "gulp watch"
  },
  "devDependencies": {
    "gulp": "^3.9.1",
    "laravel-elixir": "^5.0.0",
    "bootstrap-sass": "^3.0.0",
    "@angular/common": "2.0.0-rc.5",
    "@angular/compiler": "2.0.0-rc.5",
    "@angular/core": "2.0.0-rc.5",
    "@angular/forms": "0.3.0",
    "@angular/http": "2.0.0-rc.5",
    "@angular/platform-browser": "2.0.0-rc.5",
    "@angular/platform-browser-dynamic": "2.0.0-rc.5",
    "@angular/router": "3.0.0-rc.1",
    "@angular/router-deprecated": "2.0.0-rc.2",
    "@angular/upgrade": "2.0.0-rc.5",
    "systemjs": "0.19.27",
    "core-js": "^2.4.0",
    "reflect-metadata": "^0.1.3",
    "rxjs": "5.0.0-beta.6",
    "zone.js": "^0.6.12"
  },
  "dependencies": {
    "elixir-typescript": "^2.0.0"
  }
}

这是我的 tsconfig.json(我放入资源/资产/打字稿):

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules"
  ]
}

最后我得到了我的 gulpfile.js:

var elixir = require('laravel-elixir');
var elixirTypscript = require('elixir-typescript');

elixir(function(mix) {
    mix.sass('app.scss');

    mix.typescript('main.ts', 'public/js/');

    mix.copy('node_modules/@angular', 'public/js/angular');
    mix.copy('node_modules/when/es6-shim', 'public/js/es6-shim');
    mix.copy('node_modules/es6-promise', 'public/js/es6-promise');
    mix.copy('node_modules/rxjs', 'public/js/rxjs');
    mix.copy('node_modules/systemjs', 'public/js/systemjs');
    mix.copy('node_modules/zone.js', 'public/js/zone.js');

});

当我从控制台启动 gulp 时,我收到很多错误,例如:

/var/www/chat/laravel/node_modules/@angular/common/src/directives/ng_class.d.ts(81,34): error TS2304: Cannot find name 'Set'.
[14:59:24] gulp-notify: [Laravel Elixir] TypeScript Compilation Failed!: /var/www/chat/laravel/node_modules/@angular/common/src/directives/ng_class.d.ts(81,34): error TS2304: Cannot find name 'Set'.
{ [TypeScript error: /var/www/chat/laravel/node_modules/@angular/common/src/directives/ng_class.d.ts(81,34): error TS2304: Cannot find name 'Set'.]
  name: 'TypeScript error',
.....

似乎它试图编译 node_modules 中的所有打字稿内容。我在 tsconfig.json 中使用了“排除”字段,但它似乎不起作用。

【问题讨论】:

    标签: laravel angular typescript gulp laravel-elixir


    【解决方案1】:

    我遇到了同样的问题,但在这里解决了。

    https://github.com/axiskafi/angular2-laravel5

    您的 package.json 和 gulp 文件需要修改。按照给定的链接和说明,它将解决您的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      • 2016-03-05
      • 2017-12-09
      • 2018-11-29
      相关资源
      最近更新 更多