【问题标题】:Can not locate typescript external modules in bower package在 bower 包中找不到打字稿外部模块
【发布时间】:2015-02-13 06:29:53
【问题描述】:

我用打字稿源(外部模块)制作了一个凉亭包。在另一个项目中,我使用

安装了我的 bower 包
bower install wrath

并使用 amd require 引用该软件包。

import Model = require('wrath/Model');

然后 tsc 编译器给出错误error TS2307: Cannot find external module。我不知道如何让编译器知道它应该在 bower_components 文件夹中查找该模块。

我有一个这样的文件夹结构。

app
    main.ts
bower_components
    wrath
        Model.ts
        View.ts
        ...

有没有人可以解决这个问题?

我实际上找到了一种解决此问题的方法,方法是在应用程序目录旁边创建一个 bower 包目录的符号链接。寻找更好的方法。

【问题讨论】:

  • 你有没有想出一个好的解决方案?

标签: requirejs typescript amd


【解决方案1】:

我不知道如何让编译器知道它应该在 bower_components 中查找该模块

目前除了硬引用没有其他解决方案:

import Model  = require('./bower_components/wrath/Model');

注意:非常希望支持node_modules : https://github.com/Microsoft/TypeScript/issues/247

注意:grunt-ts 可以帮你做这些参考:https://github.com/TypeStrong/grunt-ts#transforms

【讨论】:

  • grunt-ts 转换看起来相当复杂,需要对源代码进行许多修改。如果目前没有更好的解决方案,也许我现在会坚持我的符号链接解决方案。
  • 酷。提示:我希望require('wrath/Model'); 在运行时失败。除非您使用node_modules 而不是bower_components。但是您可能正在使用可以正确解决它的东西。
  • Requirejs 可以这样设置。 requirejs.config({ baseUrl: './app', packages: [ { name: 'wrath', location: '../bower_components/wrath/src' } ] }); 如果 tsc 有类似的选项就好了。
  • 我正在为 bower+amd+typescript 苦苦挣扎,我已将其归结为所有 /bower_components/ 引用需要在 bower 展平结构后变为 /../ 引用(以避免打字、deps、路径)。太糟糕了,TSC 不知道 bower_components。
猜你喜欢
  • 2014-09-28
  • 1970-01-01
  • 2021-01-07
  • 2013-12-30
  • 2018-06-27
  • 2021-03-16
  • 1970-01-01
相关资源
最近更新 更多