React-apollo: 2.x requires unstated dependency @types/lodash.flowright

Created on 25 Oct 2017  路  38Comments  路  Source: apollographql/react-apollo

Intended outcome:
Upgrading from 1.x release to the 2.x release.

Actual outcome:

Error at node_modules/react-apollo/browser.d.ts:6:26: Could not find a declaration file for module 'lodash.flowright'. '/Users/x/x/node_modules/lodash.flowright/index.js' implicitly hasan 'any' type.
  Try `npm install @types/lodash.flowright` if it exists or add a new declaration (.d.ts) file containing `declare module 'lodash.flowright';`

How to reproduce the issue:

Install react apollo in a typescript project and run tsc

Version

Most helpful comment

It looks like the compiler didn't catch this (and many other instances like it) because the noImplicitAny compiler option isn't being used. Unfortunately, installing @types/lodash.flowright won't resolve it and results in an error [ts] Module '"/path/to/node_modules/@types/lodash.flowright/index"' resolves to a non-module entity and cannot be imported using this construct.

Using the lodash-es package (instead of lodash or lodash.flowright) along with the @types/lodash-es package will allow specific functions to be imported in ES modules and compile without error when the noImplicitAny compiler option is used.

- import * as compose from 'lodash.flowright'; 
- export { compose }; 
+ import flowRight from 'lodash-es/flowRight';
+ export { flowRight as compose };

If there is agreement on this approach, I don't mind working on a PR.

All 38 comments

Confirm error

It looks like the compiler didn't catch this (and many other instances like it) because the noImplicitAny compiler option isn't being used. Unfortunately, installing @types/lodash.flowright won't resolve it and results in an error [ts] Module '"/path/to/node_modules/@types/lodash.flowright/index"' resolves to a non-module entity and cannot be imported using this construct.

Using the lodash-es package (instead of lodash or lodash.flowright) along with the @types/lodash-es package will allow specific functions to be imported in ES modules and compile without error when the noImplicitAny compiler option is used.

- import * as compose from 'lodash.flowright'; 
- export { compose }; 
+ import flowRight from 'lodash-es/flowRight';
+ export { flowRight as compose };

If there is agreement on this approach, I don't mind working on a PR.

Same error here. The Typescript type definition errors are kinda ruining the fun of experimenting with an apollo integration

Just encountered this same error and used the above fix in my node_modules. Have you started a PR for this? @corydeppen

Not yet. I wanted to see if there was agreement on the approach first, but haven't heard anything yet.

@inakianduaga it's kinda is. Hope this will be resolved soon. For now probably best to downgrade to 1.4.16 where typings are just fine. Migration back to v2 should be quite straightforward later as looks like there aren't really many breaking changes.

Tried the solution proposed by @corydeppen and it works. Can we go ahead and make a PR for this?

This issue has been automatically labled because it has not had recent activity. If you have not received a response from anyone, please mention the repository maintainer (most likely @jbaxleyiii). It will be closed if no further activity occurs. Thank you for your contributions to React Apollo!

@jbaxleyiii When you have a few minutes, please review my last comment on PR #1344 regarding increasing the bundle size.

Any possible hotfixes?

I'm going to make sure this gets fixed today and is released! Sorry for the delay! The post 2.0 launch has been SO busy with projects popping up everywhere!

Actually there are still a problem with lodash-es since it required babel to run on node and this doesn't work well with next.js

Any known workarounds while this issue gets resolved?

@danielrasmuson You can add

declare module 'lodash.flowright';

to a d.ts file to silence the warning in the meantime.

Do believe this should be re-opened since the fix has been reverted.

Same issue, should re-open until fix it.

Until this is fixed I did the following and it is working for me. Replace the following code

import * as compose from 'lodash.flowright';
export { compose };

with

import { flowRight } from "lodash";
export default flowRight; 

in browser.d.ts.

I opened #1445 since this issue is closed and does not seem to get any attention.

Watchers please check and discuss my comment https://github.com/apollographql/react-apollo/pull/1478#issuecomment-354132340 in the PR.

Please re-open, same issue!

It's fixed on master, which removes it and is unreleased, therefore this issue is closed.

See previous linked PR which states the migration path.

@rosskevin can we please have a hotfix release soon? This is a pretty obvious and annoying bug.

I fixed it by adding an empty declaration as @asmockler suggested above. While that get rids of the error, it's still a hack.

@rosskevin Actually this was re-added in https://github.com/apollographql/react-apollo/pull/1572 so we are back to square one. It's kind of annoying but the declare module 'lodash.flowright'; works :)

@rosskevin Any reason why #1572 re-added the broken re-export of compose from lodash.flowright?

@jbaxleyiii didn't want any breaking changes in the next release. It will be removed in the next major.

3 months down the track and it's still an issue :(

I had to rewrite my app to something else like Flow to avoid this issue :(

@wongmjane that sounds a little bit drastc 馃槄 adding a declare module 'lodash.flowright'; in a types.d.ts file is probably a reasonable workaround while this is addressed

The fast way of resolving this is to add "noImplicitAny": false, to tscongfig.json, but if you have any better suggestions I will highly appreciate them. I really don't want to allow any in my project.

@kamenminkovcom see comment above yours

I am new to ts, so sorry if I am asking stupid things but when I add types.d.ts file there is an error. Should I add the file path to my tsconfig.json and in which particular property?

just as you would include other files: include/exclude/files properties on tsconfig

@kamenminkovcom I added the following file and my TypeScript compiler doesn't complain anymore. No noImplicitAny: false is needed:

// apollo-react-lodash-fix.d.ts

declare module 'lodash.flowright';

Is there an ETA for the fix... This is a bit troubling for new comers.

Came across this issue today when using create-react-app v1.1.5.

declare module 'lodash.flowright' didn't work. I needed

declare module 'lodash/flowRight'

Dependencies:

"apollo-boost": "^0.1.16",
"graphql": "^14.0.2",
"graphql-tag": "^2.9.2",
"react-apollo": "^2.2.1"

Problem still exist after upgrade to react-apollo v 2.2.2

Solution for me: downgrade to 2.1.11

Problem still exist after upgrade to react-apollo v 2.2.2

Solution for me: downgrade to 2.1.11

Worked for me as well thanks

it works in version 2.2.4.
Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

voodooattack picture voodooattack  路  3Comments

dmitryyankowski picture dmitryyankowski  路  3Comments

mpgon picture mpgon  路  3Comments

tomitrescak picture tomitrescak  路  3Comments

notadamking picture notadamking  路  3Comments