打字稿意外令牌<

时间:2016-11-23 08:51:16

标签: typescript compiler-errors jsx tsx

我使用mocha从命令行测试tsx组件。 我用于编译ts-node包。但它无法兼容jsx。我的tsconfig.json有jsx编译选项。

  

mocha --compilers ts:ts-node / register,tsx:ts-node / register,js:babel-core / register ./src/testing.tsx

SyntaxError:意外的令牌<     在exports.runInThisContext(vm.js:53:16)

tsconfig.json:

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "module": "commonjs",
    "jsx": "preserve",
    "target": "es6",
    "removeComments": true,
    "preserveConstEnums": true,
    "sourceMap": false,
    "noEmitHelpers": false,
    "noEmitOnError": false,
    "noImplicitAny": false
  },
  "exclude": [
    "babel_cache",
    "build",
    "docs",
    "gradle",
    "node_modules",
    "out",
    "test",
    "tools",
    "typings"
  ],
  "compileOnSave": false,
  "buildOnSave": false
}

/src/testing.tsx:

import * as React from 'react';
class Foo extends React.Component<any, any> {
    render () {
        return <span>yep</span>;
    }
}
<Foo />

0 个答案:

没有答案