Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tsc crash when mixing fp-ts/lib & fp-ts/es6 #860

Closed
jollytoad opened this issue May 7, 2019 · 4 comments
Closed

Tsc crash when mixing fp-ts/lib & fp-ts/es6 #860

jollytoad opened this issue May 7, 2019 · 4 comments

Comments

@jollytoad
Copy link

Do you want to request a feature or report a bug?

bug

What is the current behavior?

If I import a module from fp-ts/es6 and also another module that indirectly imports the same module but from fp-ts/lib, the tsc compiler goes crazy and eventually crashes with a heap allocation failure (often after several minutes).

I've found this when using both io-ts and fp-ts-rxjs.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://codesandbox.io/ or similar.

import {observable} from 'fp-ts-rxjs/lib/Observable'
import {right} from 'fp-ts/es6/Either'

What is the expected behavior?

not to crash!

Which versions of fp-ts, and which browser and OS are affected by this issue? Did this work in previous versions of fp-ts?

fp-ts: 1.17.3
fp-ts-rxjs: 0.5.1
io-ts: 1.8.5

@jollytoad
Copy link
Author

jollytoad commented May 7, 2019

I think i may have found a work-around, by setting a path in the tsconfig...

{
  "compilerOptions": {
    "paths": {
      "fp-ts/lib/*": [ "node_modules/fp-ts/es6/*" ],
      "*": [ "node_modules/*" ]
   }
}

I'll see how it goes with this and report back.

@jollytoad
Copy link
Author

So, i can confirm this fixes all the crashes i had when mixing io-ts or fp-ts-rxjs with fp-ts/es6 modules.

Maybe it's something that could be added to the caveats of the es6 module usage in case anyone hits the problem.

Oh, and on the issue of es6 caveats, regarding jest, you need to add the follow jest config...

    "transformIgnorePatterns": [
      "<rootDir>/node_modules/(?!(fp-ts/es6)/)"
    ],

@wmaurer
Copy link
Contributor

wmaurer commented Jul 2, 2019

@jollytoad Thanks for your tsconfig.json work-around ("fp-ts/lib/*": [ "node_modules/fp-ts/es6/*" ]).

This in fact, fixes much more than the tsc crashing that you experienced. In my app which uses webpack to bundle, it also fixes inconsistencies which otherwise end up in the bundle!

For example, if I have a project that uses io-ts, and I import from io-ts/es6 and call the decode method on a runtime type, I get an Either return type. When I analyse this with webpack-bundle-analyzer, I see this (io-ts v1):

image

Ouch! I'm importing from io-ts/es6 but am getting fp-ts/lib in the bundle. After your fix, I see

image

Much better!

Similar with io-ts v2. Before:
image

After:

image

Also much better!

This says to me that something is somewhere wrong with the es6 bundling in the fp-ts ecosystem, but at this moment I've no idea how it can be resolved. All I know is that if I import from io-ts/es6, I'd ideally like fp-ts/es6 in my bundle.

Your work-around works well enough for me though ;-)

@jjm340
Copy link

jjm340 commented Nov 22, 2019

So, i can confirm this fixes all the crashes i had when mixing io-ts or fp-ts-rxjs with fp-ts/es6 modules.

Maybe it's something that could be added to the caveats of the es6 module usage in case anyone hits the problem.

Oh, and on the issue of es6 caveats, regarding jest, you need to add the follow jest config...

    "transformIgnorePatterns": [
      "<rootDir>/node_modules/(?!(fp-ts/es6)/)"
    ],

Thanks a ton for this, was pulling my hair out trying to get this to work with jest!

Edit: It actually didn't work for me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants