rollup-plugin-typescript2: Does not work with async plugins

What happens and why it is wrong

This plugin does not work with plugin which containing async/await syntax caused by object-hash issue and tscache.ts. I think this is hard to fix object-hash because there is no way to detect asyncfunction now. So is there any alternative without object-hash?

Environment

Versions

  • typescript: 2.8.3
  • rollup: 2.1.1
  • rollup-plugin-typescript2: 0.14.0

rollup.config.js

import svgr from '@svgr/rollup';
import typescript from 'rollup-plugin-typescript2';

export default {
  // ...
  plugins: [
    replace({ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) }),
    svgr(),
    typescript({
      useTsconfigDeclarationDir: true,
    })
  ],
  // ...
};

tsconfig.json

No relevant.

package.json

No relevant.

plugin output with verbosity 3

[!] (rpt2 plugin) Error: Unknown object type "asyncfunction"
src/components/atoms/Icon/index.ts
Error: Unknown object type "asyncfunction"
    at Object._object (/Users/vwxyutarooo/Projects/kouzoh/mercari-web-jp-component/node_modules/rollup-plugin-typescript2/node_modules/object-hash/index.js:218:17)
    at Object._function (/Users/vwxyutarooo/Projects/kouzoh/mercari-web-jp-component/node_modules/rollup-plugin-typescript2/node_modules/object-hash/index.js:319:14)
    at Object.dispatch (/Users/vwxyutarooo/Projects/kouzoh/mercari-web-jp-component/node_modules/rollup-plugin-typescript2/node_modules/object-hash/index.js:185:30)
    at /Users/vwxyutarooo/Projects/kouzoh/mercari-web-jp-component/node_modules/rollup-plugin-typescript2/node_modules/object-hash/index.js:246:18
    at Array.forEach (<anonymous>)
    at Object._object (/Users/vwxyutarooo/Projects/kouzoh/mercari-web-jp-component/node_modules/rollup-plugin-typescript2/node_modules/object-hash/index.js:242:21)
    at Object.dispatch (/Users/vwxyutarooo/Projects/kouzoh/mercari-web-jp-component/node_modules/rollup-plugin-typescript2/node_modules/object-hash/index.js:185:30)
    at /Users/vwxyutarooo/Projects/kouzoh/mercari-web-jp-component/node_modules/rollup-plugin-typescript2/node_modules/object-hash/index.js:260:23
    at Array.forEach (<anonymous>)
    at Object._array (/Users/vwxyutarooo/Projects/kouzoh/mercari-web-jp-component/node_modules/rollup-plugin-typescript2/node_modules/object-hash/index.js:259:20)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 4
  • Comments: 15 (12 by maintainers)

Commits related to this issue

Most upvoted comments

I must admit I’m surprised this haven’t been more of an issue so far since async functions are extremely common by now 😀. Which is also why I think that simply ignoring it will lead to a great deal of cache issues. The PR I submitted to object-hash some time ago was a consequence of this very issue, and I would suggest that you remove the dependency on object-hash. I’m pretty confident that the PR submitted some time ago would work just fine since it matches on the same value as provided in the error message and passed both unit tests and solved the issues in this plugin, so feel free to depend on the PR rather than the NPM package here.

@vwxyutarooo, an immediate workaround is to set clean: true in the config to bypass the cache completely. Alternatively (sorry for the plug) I built https://github.com/wessberg/rollup-plugin-ts which will also work just fine

Thought I’d add an update for folks here that the root cause here was finally fixed in https://github.com/puleos/object-hash/pull/90 (very similar to https://github.com/puleos/object-hash/pull/68 referenced above) and here in #203. No need to use objectHashIgnoreUnknownHack to support async plugins and no more cache issues – was just released as v0.26.0 🎉 😄

In 0.17.0 now

For another workaround not using the objectHashIgnoreUnknownHack hack, I ran into this problem using rollup-plugin-require-context, and the following snippet seems to work:

import requireContextORIGINAL from 'rollup-plugin-require-context'

const requireContext = (options) => {
  const plugin = requireContextORIGINAL(options)
  return {
    name: plugin.name,
    transform(code, id) {
      return plugin.transform(code, id)
    }
  }
}

Namely, making transform a normal function returning a promise.

@vwxyutarooo, I was under the assumption that clean: true uses a noop cache strategy. That’s what I remember that @ezolenko implemented some time ago. If it still attempts to compute a cache key from the rollup config, that behavior needs looking into in my opinion

I added a workaround to ignore anything object-hash can’t process (see objecthash branch, objectHashIgnoreUnknownHack option). This can potentially make cache stale though, so not a good long term solution.