Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clash with rollup-plugin-typescript2? #16

Closed
lazarljubenovic opened this issue Apr 10, 2019 · 4 comments
Closed

Clash with rollup-plugin-typescript2? #16

lazarljubenovic opened this issue Apr 10, 2019 · 4 comments

Comments

@lazarljubenovic
Copy link

I created a barebones project with Typescript.

tsconfig.json
{
  "compilerOptions": {
    "target": "es6",
    "module": "esnext",
    "rootDir": "./src",
    "strict": true,
     "esModuleInterop": true
  }
}
package.json
  "devDependencies": {
    "rollup": "^1.9.3",
    "rollup-plugin-copy": "^1.0.0",
    "rollup-plugin-typescript2": "^0.20.1",
    "typescript": "^3.4.3"
  }

With src/index.html and src/index.ts present, I am getting the following error.

[!] (rpt2 plugin) Error: Unknown object type "asyncfunction"
src/index.ts
Error: Unknown object type "asyncfunction"
    at Object._object (/home/lazar/basketball/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:23691:17)
    at Object._function (/home/lazar/basketball/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:23792:14)
    at Object.dispatch (/home/lazar/basketball/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:23658:30)
    at /home/lazar/basketball/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:23719:18
    at Array.forEach (<anonymous>)
    at Object._object (/home/lazar/basketball/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:23715:21)
    at Object.dispatch (/home/lazar/basketball/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:23658:30)
    at /home/lazar/basketball/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:23733:23
    at Array.forEach (<anonymous>)
    at Object._array (/home/lazar/basketball/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:23732:20)

1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Here's the config.

import typescript from 'rollup-plugin-typescript2'
import copy from 'rollup-plugin-copy'

export default {
  input: 'src/index.ts',
  output: {
    file: 'dist/bundle.js',
    format: 'iife',
  },
  plugins: [
    copy({
      targets: [
        'src/index.html',
      ],
      outputFolder: 'dist',
    }),
    typescript({
      typescript: require('typescript'),
    }),
  ]
}

Commenting out any of the plugins make it work properly. This error was mentioned in ezolenko/rollup-plugin-typescript2#105, but the rationale given seems irrelevant to this issue.

@vladshcherbin
Copy link
Owner

vladshcherbin commented Apr 10, 2019

The issue is with rollup-plugin-typescript2 plugin, the linked issue is exactly what it is.

In the docs, there is a Compatibility / plugins using async/await section which points to using objectHashIgnoreUnknownHack option to fix this. The linked issue was also resolved with this.

So, the solution is to try this option. Not sure I can fix this somehow in rollup-plugin-copy.

@vladshcherbin
Copy link
Owner

@lazarljubenovic I tried it and it actually works:

typescript({
  typescript: require('typescript'),
  objectHashIgnoreUnknownHack: true,
}),
Full config
import typescript from 'rollup-plugin-typescript2'
import copy from 'rollup-plugin-copy'

export default {
  input: 'src/index.ts',
  output: {
    file: 'dist/bundle.js',
    name: 'myLibrary',
    format: 'iife',
  },
  plugins: [
    copy({
      targets: [
        'src/index.html',
      ],
      outputFolder: 'dist',
    }),
    typescript({
      typescript: require('typescript'),
      objectHashIgnoreUnknownHack: true,
    }),
  ]
}

Change this in your config and it should work too 😉

@lazarljubenovic
Copy link
Author

I skimmed too quickly, I thought it was about async in code, not plugins. Sorry and thanks 😅

@tonysamperi
Copy link

@lazarljubenovic I tried it and it actually works:

typescript({
  typescript: require('typescript'),
  objectHashIgnoreUnknownHack: true,
}),

Full config
Change this in your config and it should work too 😉

Thanks, it worked. Very wierd we need to do this, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants