您可能需要适当的加载程序来处理此文件类型。打字稿

时间:2017-05-07 18:59:09

标签: angular typescript coffeescript

我正在尝试在这里为你的Youtube Data API使用Typescript打字:https://github.com/Bolisov/typings-gapi/tree/master/gapi.client.youtube-v3

我正在使用Ionic框架,我在使用以下代码行进行Ionic Serve后收到以下错误:

  gapi.client.load("client", "v3");

Module parse failed: /Users/yoko/Desktop/myApp/node_modules/gapi/lib/gapi.coffee Unexpected token (1:17)
You may need an appropriate loader to handle this file type.
| config = require './config'
| 
| module.exports = 

这就是api.coffee的样子

config = require './config'

module.exports =
  server:
    setApiKey: (apiKey) ->
      config.api.key = apiKey
    load: (apiName, apiVersion, callback) ->
      @[apiName] = require "./#{apiName}/#{apiVersion}"
      callback()

这是什么意思?

1 个答案:

答案 0 :(得分:1)

假设您使用的是Gulp,请通过npm安装CoffeeScript,然后通过以下方式将其添加到package.json

npm install gulp-coffee --save-dev #devDependencies

npm install gulp-coffee --save #dependencies

然后将以下内容添加到您的Gulpfile.js:

var coffee = require('gulp-coffee');
var paths =  { coffee: ['/Users/yoko/Desktop/myApp/node_modules/gapi/lib/*.coffee'] };

function coffeePipe(done) 
  {
  gulp.src(paths.coffee)
    .pipe(coffee({bare: true})
    .on('error', gutil.log.bind(gutil, 'Coffee Error')))
    .pipe(concat('application.js'))
    .pipe(gulp.dest('./www/js'))
    .on('end', done)
  }

gulp.task('coffee', coffeePipe);

<强>参考