react-apollo icon indicating copy to clipboard operation
react-apollo copied to clipboard

Attempted import error: 'compose' is not exported from 'react-apollo'

Open luizdanieldesouza opened this issue 7 years ago • 7 comments

After upgrading react-apollo to 3.0.0 the following error message is presented:

Attempted import error: 'compose' is not exported from 'react-apollo'

luizdanieldesouza avatar Aug 08 '19 23:08 luizdanieldesouza

@luizdanieldesouza compose was removed from React Apollo 3 (see the Breaking Changes section of the Changelog). If you want to keep using compose though, it was just a copy of lodash's flowRight.

hwillson avatar Aug 09 '19 00:08 hwillson

@hwillson any idea why it was removed? I'd like to know what is the best practice now because the documentation on https://www.apollographql.com still using compose in their examples.

victors1681 avatar Aug 17 '19 19:08 victors1681

@victors1681 It was removed to help reduce the React Apollo bundle size. Since compose was really just a copy of lodash's flowRight, it didn't make sense to keep it in the bundle. Especially when not everyone wanted to use it and when it's quite easy to add flowRight into a project (and alias it as compose if you want to):

npm install lodash.flowright
import * as compose from 'lodash.flowright';

hwillson avatar Aug 19 '19 13:08 hwillson

import * as compose from 'lodash.flowright';

For some reason this didn't work for me. I had to use: import flowright from "lodash.flowright";

And simply rename compose to flowRight.

rooch84 avatar Aug 20 '19 10:08 rooch84

Thanks! It worked for me.

brenopgarcia avatar Oct 06 '19 14:10 brenopgarcia

@rooch84 any default import can be named whatever you want. these are all equivalent: The reason @hwillson is probably using the * as notation is TypeScript.

import flowright from "lodash.flowright";
import foobar from "lodash.flowright";
import compose from "lodash.flowright";

Falieson avatar Oct 17 '19 17:10 Falieson

Thanks for the clarification.

rooch84 avatar Oct 17 '19 21:10 rooch84