Rollup typescript decorators support

Viewed 1375

I get following error message:

Error: Parse Error: Line 29: Unexpected token ILLEGAL

the corresponding line of code is mobx observer decorator:

@observer
class Wrapper extends Component<IProps> {

I have following 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:

{
  "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.

1 Answers

Not 100% certain this applies since my error was slightly different (Error: Unexpected character '@').

But what solved the issue with rollup together with TypeScript decorators was removing the outDir option from tsconfig.json.

Related