1 year ago

#66473

test-img

Simon

importing hybrid package in react native/typescript/expo

I'm trying to import the library fp-ts-std but my import fails.

The readme refers to conditional exports, that is: the library exports 2 versions. More thoroughly explained here.

  • One for cjs in fp-ts-std/dist/cjs
  • One for ES-modules in fp-ts-std/dist/esm

I can import my function from the specified sub-directory "fp-ts-std/dist/esm", however without typechecking, which defeats the purpose of the library. If i import from fp-ts-std/Record, typescript checks out but i get the error

Unable to resolve module fp-ts-std/Record

I have tried setting moduleResolution in tsconfig to "node12" or "nodenext", however this flag isn't even available when I'm using the latest development version of typescript.

My project uses typescript, react native and expo.

  1. How do i find out if my environment supports conditional imports?
  2. Is there a solution?

To replicate:

npm i expo-cli -g
expo init hybrid-test-app
npm i fp-ts-std --save

In any file:

import {pick} from "fp-ts-std/Record";
pick(["hello"], {hello: "world"}

The resulting package.json. The tsconfig inherits from this file. I don't think these are the problem though, as i have seen working projects with identical tsconfig, but without expo.

typescript

expo

es6-modules

fp-ts

0 Answers

Your Answer

Accepted video resources