【问题标题】:Unable to use the build version of tsc compile无法使用 tsc compile 的构建版本
【发布时间】:2016-06-06 12:48:08
【问题描述】:

我正在将所有文件的 ts 版本构建到一个文件中并尝试使用它。但它不适用于那个。正常的工作。这是 tsconfig:

 "compilerOptions": {
    "target": "ES5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "declaration": true,
"outDir":"client/build/",
"outFile": "all.js"
  },

html加载all.js和系统导入。

<script src="client/build/all.js"></script>
<!-- 2. Configure SystemJS and Import -->
<script>
    System.config({
    packages: {        
      client: {
        format: 'register',
        defaultExtension: 'js'
      }
    }
  });
  System.import('client/build/all')
        .then(null, console.error.bind(console));
</script>

构建发生但无法加载到 index.html 文件中。还需要什么才能使其正常工作?其次是否有 tsc 的缩小? 注意:已检查Typescript compile to single file

更新

刚刚升级到 Typescript 1.9dev 并出现错误:

[0] node_modules/angular2/src/facade/promise.d.ts(1,10):错误 TS2661:无法重新导出模块中未定义的名称。 [0] client/services/httpprovider.ts(13,5): error TS4053: Return type of public method from export class has or is using name 'Observable' from external module "c:/git/projects/edureka/yeo/ 2/node_modules/rxjs/Observable”但不能命名。

更新:现在是 1.82 稳定版。

更新更新:使用捆绑配置定义(检查 Sasxa 的 cmets)-https://github.com/systemjs/systemjs/blob/master/docs/production-workflows.md

【问题讨论】:

  • 任何具体的错误信息?
  • 没有错误信息。 TS 1.5.3
  • 不确定发生了什么,你得到一个 404 loading all.js ?构建文件夹中的 all.js 文件是否存在?控制台上的任何错误最好在此处发布。试试 Typescript 1.8,因为它具有捆绑功能和稳定版本 -W github.com/Microsoft/TypeScript/wiki/… 你安装的 1.9.dev 很可能有各种陷阱,因为它是一个 alpha 版本
  • 没有 404 错误。我能够加载文件并且文件是正确构建的。但是当我做 System.import('client/build/all') 它不起作用。得到一个构建错误,当我在没有构建到一个文件的情况下正常编译时不会发生。

标签: build typescript angular out tsc


【解决方案1】:

您已经加载了捆绑的文件:

<script src="client/build/all.js"></script>

您不必使用 SystemJS 再次导入它们。

// System.import('client/build/all')

相反,您应该导入引导文件:

System.import('client/bootstrap')

(或在您的捆绑包中注册的任何名称all.js...)

【讨论】:

  • Bootstrap 也在同一个文件中。那会是'client/build/boot'还是只是注册名boot?我正在看这个,但没有太大帮助github.com/systemjs/systemjs/blob/master/docs/… 当我按照你说的做时,它并没有识别我的根组件。说选择器丢失。
  • 异常:选择器“main-app”没有匹配任何元素
  • 我相信它应该只是boot,如果它是这样注册的。我有一段时间没有使用捆绑软件,但我从我的一个旧实验中挖出了这个:System.register("scripts/app/bootstrap.js", ["angular2/platform/browser.js", .....。在这种情况下,我使用System.import('scripts/app/bootstrap') 启动应用程序...文档不是很有帮助,而且我看到的指南/教程很差(或仅涵盖基本的样板案例),所以我学到的很少是试用和错误;/我正在开发一些没有捆绑包的应用程序,并希望在我完成它们时情况会有所改善(:
  • 谢谢。我确实尝试过这个和System.register("services/userdetails",[...]System.register("boot",[...]System.register("services/httpreq",[...]client/build/all.js'.这会工作吗? .... System.config({ packages: { client: { format: 'register', defaultExtension: 'js' } } }); System.import('boot').then(null, console.error.bind(console)); bootclient/build/bootclient/build/all/boot 都出现错误:(
  • 如果不尝试并查看该项目,就无法确定发生了什么。我建议你创建一个新项目,只有 1-2 个文件,然后尝试先让它工作。当您弄清楚发生了什么以及事情如何工作时,升级您当前的项目。恐怕我不知道对此有什么“快速修复”;(
【解决方案2】:

我刚刚从网上下载了一个 MVC Angular2 示例解决方案后遇到了这个错误:

node_modules/angular2/src/facade/promise.d.ts(1,10):错误 TS2661:无法重新导出模块中未定义的名称。 [0]

根本原因是 Angular 中存在错误。 解决方案:在项目内的 Angular2 文件夹上运行 NPM 更新。

【讨论】:

    猜你喜欢
    • 2019-08-31
    • 2020-11-19
    • 1970-01-01
    • 2021-10-06
    • 2022-07-08
    • 2022-08-16
    • 2012-01-17
    • 2018-06-25
    • 1970-01-01
    相关资源
    最近更新 更多