Skip to content
This repository has been archived by the owner on Sep 22, 2021. It is now read-only.

Uncaught TypeError: Class constructor Container cannot be invoked without 'new' #1

Open
srph opened this issue May 7, 2019 · 1 comment

Comments

@srph
Copy link

srph commented May 7, 2019

Awesome work here! Render props work, but I really want to use hooks asap.


I'm trying to use this with Parcel, with this code:

import { Container } from '@gitbook/unstated'

class X extends Container {
  log() {
    console.log('X:log')
  }
}

const x = new X()
x.log()

But I ran into an error:

Uncaught TypeError: Class constructor Container cannot be invoked without 'new'

I guess it's because Parcel doesn't transpile third-party packages.

Reproducible Bug

I made a reproducible repo here.

Workaround

I'm not sure how to fix this through rollup (haha sorry!), but I'm trying to find out how. For the mean time, hope someone may find this useful.

I'm directly importing the ts file like so:

import { Container } '@gitbook/unstated/dist/index'

Since I don't know how to make Parcel's package alias work, I re-exported it through another file.

// src/lib/unstated/index.ts
export * from '@gitbook/unstated/dist/index'

// src/containers/AuthStore
import { useUnstated } from '~/lib/unstated'

Hope this helps out someone for the mean time.

@srph
Copy link
Author

srph commented May 7, 2019

Nevermind. My workaround doesn't work. Bottomline is we need a way to transpile classes to class functions.

@srph srph mentioned this issue May 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant