“意外的令牌导出";在带有SystemJS和TypeScript的Angular应用中 [英] "Unexpected token export" in Angular app with SystemJS and TypeScript

查看:57
本文介绍了“意外的令牌导出";在带有SystemJS和TypeScript的Angular应用中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在plunker中运行的Angular示例中碰巧遇到了此错误,其中SystemJS在浏览器中转译了TypeScript代码.

I happened to get this error in an Angular example running in plunker where SystemJS transpiles TypeScript code in the browser.

在本地运行良好的代码没有任何问题.

推荐答案

解决方案

这不是一个Angular问题.在浏览器中转译某些类型的TypeScript文件是一个问题.

Solution

This isn't an Angular problem. It's a problem with transpiling certain kinds of TypeScript files in the browser.

就我而言,我将问题归结为一个文件,该文件仅导出了抽象类 .

In my case, I tracked the problem down to a single file that only exported an abstract class.

// Class used as a "narrowing" interface that exposes a minimal logger
// Other members of the actual implementation are invisible
export abstract class MinimalLogger {
  logs: string[];
  logInfo: (msg: string) => void;
}

问题在于此文件除抽象类外不会导出任何其他.

The problem is that this file doesn't export anything other than the abstract class.

当我添加任何具体内容的惰性输出时,如下所示:

When I add an inert export of anything concrete ... like this:

export const _ = 0; // hack: must export something "real"

...错误消失了.

我已经看到了一个仅导出TypeScript接口的文件的类似问题.您必须给它至少一件真实"的东西.

I've seen a similar problem with a file that only exports TypeScript interfaces. You have to give it at least one thing that is "real".

环境:

  • typescript@2.2.1
  • systemjs@0.19.39

此示例的SystemJS Config:

SystemJS Config for this example:

 System.config({
    // DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
    transpiler: 'ts',
    typescriptOptions: {
      "target": "es5",
      "module": "commonjs",
      "moduleResolution": "node",
      "sourceMap": true,
      "emitDecoratorMetadata": true,
      "experimentalDecorators": true,
      "lib": ["es2015", "dom"],
      "noImplicitAny": true,
      "suppressImplicitAnyIndexErrors": true
    },
    meta: {
      'typescript': {
        "exports": "ts"
      }
    },
    ...
  })

这篇关于“意外的令牌导出";在带有SystemJS和TypeScript的Angular应用中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆