matthewp / haunted

React's Hooks API implemented for web components 👻

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with ESM libraries using only React default export

atoy40 opened this issue · comments

Hello,

I'm trying to use Haunted with the react-apollo hooks library, but I think it can be an issue with a lot of other "hooks" libraries :

I use Webpack to alias react to haunted, but in the apollo library, they use :

import React from 'react';

and then they call React.createContext() or React.useXXXX(). The problem is Haunted default export doesn't contains thoses methods.
I'm not sure if it is a problem into the apollo library (may be they have to use * as React instead of React ? or may be haunted has to export functions into the default object ?

I also tried to force the usage of the commonJS version of the apollo library, but it falls to the same issue because it detect Haunted is a "__esModule" and then the require extract the default export from haunted.

Thanks for help.

Anthony.

Just as a workarround, I added an "intermediate" module into my project containing :

import * as Haunted from 'haunted';

export default {
    useState: Haunted.useState,
    useContext: Haunted.useContext,
    createContext: Haunted.createContext,
};

export * from 'haunted';

And this is this one I aliased over react module. I've only added 3 function to the default export because this is thoses needed by react-apollo.