简体   繁体   English

汇总打字稿装饰器支持

[英]Rollup typescript decorators support

I get following error message:我收到以下错误消息:

Error: Parse Error: Line 29: Unexpected token ILLEGAL错误:解析错误:第 29 行:意外令牌非法

the corresponding line of code is mobx observer decorator:对应的代码行是 mobx 观察者装饰器:

@observer
class Wrapper extends Component<IProps> {

I have following rollup.config.js:我有以下 rollup.config.js:

import typescript from 'rollup-plugin-typescript2'
import jsx from 'rollup-plugin-jsx'
import pkg from './package.json'
export default {
  input: 'src/index.ts',
  output: [
    {
      file: pkg.main,
      format: 'cjs',
    },
    {
      file: pkg.module,
      format: 'es',
    },
  ],
  external: [
    ...Object.keys(pkg.dependencies || {}),
    ...Object.keys(pkg.peerDependencies || {}),
  ],
plugins: [
    jsx( {factory: 'React.createElement'} ),
    typescript({
      typescript: require('typescript'),
    }),
  ],
}

my tsconfig.json:我的 tsconfig.json:

{
  "compilerOptions": {
    "declaration": true,
    "declarationDir": "./dist",
    "module": "es6",
    "experimentalDecorators": true,
    "outDir": "./dist",
    "target": "es5",
    "jsx": "react",
    "types": ["reflect-metadata", "node"],
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "strictPropertyInitialization": false,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "noEmit": true,
    "emitDecoratorMetadata": true,
    "noEmitHelpers": true,
    "importHelpers": true,
    "sourceMap": true,
    "noImplicitReturns": false,
    "noImplicitThis": false,
    "noImplicitAny": false,
    "strictNullChecks": false,
    "suppressImplicitAnyIndexErrors": false,
    "noUnusedLocals": true
  },
  "include": [
    "src/**/*"
  ],
  "exclude": ["node_modules"]
}

As of documentation tells, https://github.com/ezolenko/rollup-plugin-typescript2 plugin should take all the options from my tsconfig.json file, also "experimentalDecorators": true, but does not seem to work.根据文档说明, https://github.com/ezolenko/rollup-plugin-typescript2插件应该从我的 tsconfig.json 文件中获取所有选项,还有“experimentalDecorators”:true,但似乎不起作用。

Not 100% certain this applies since my error was slightly different ( Error: Unexpected character '@' ).不是 100% 确定这适用,因为我的错误略有不同( Error: Unexpected character '@' )。

But what solved the issue with rollup together with TypeScript decorators was removing the outDir option from tsconfig.json .但是通过汇总与 TypeScript 装饰器一起解决的问题是从tsconfig.json删除outDir选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM