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

2.13 'lib' import errors in Jest #1786

Comments

@thewilkybarkid
Copy link
Contributor

Just tried upgrading a project to 2.13.0-rc.4 to see what happens, and found that the old-style fp-ts/lib/ imports in io-ts cause Jest to fail:

Test suite failed to run

ENOENT: no such file or directory, open '[...]/node_modules/fp-ts/lib/lib/Either.js'

  at Runtime.readFile (node_modules/jest-runtime/build/index.js:2574:21)
  at Object.<anonymous> (node_modules/io-ts/lib/Decoder.js:27:22)

It might happen with other packages too (e.g. logging-ts), but it's probably not reached them yet.

Given the project runs successfully (with Node 16.17.0), this could be a Jest problem (or a problem with our configuration), but I thought it worth flagging here.

@gcanti
Copy link
Owner

gcanti commented Sep 20, 2022

Thanks @thewilkybarkid, I think the culprit might be 87455b8, I'll revert that change too

@gcanti
Copy link
Owner

gcanti commented Sep 20, 2022

@thewilkybarkid ok, I reverted the build change in 87455b8, updated the exports field accordingly... (/cc @viell-dev)

"exports": {
    ".": {
      "require": "./lib/index.js",
      "import": "./es6/index.js",
      "types": "./lib/index.d.ts"
    },
    "./HKT": {
      "require": "./lib/HKT.js",
      "import": "./es6/HKT.js",
      "types": "./HKT.d.ts"
    },
    "./*": {
      "require": "./lib/*.js",
      "import": "./es6/*.js",
      "types": "./lib/*.d.ts"
    },
    "./es6/HKT": {
      "import": "./es6/HKT.js",
      "types": "./HKT.d.ts"
    },
    "./es6/*": {
      "import": "./es6/*.js",
      "types": "./lib/*.d.ts"
    },
    "./lib/HKT": {
      "require": "./lib/HKT.js",
      "types": "./HKT.d.ts"
    },
    "./lib/*": {
      "require": "./lib/*.js",
      "types": "./lib/*.d.ts"
    }
  }

...and released 2.13.0-rc.5 (fingers crossed)

EDIT

p.s.
The issue with bind/bindW should be fixed

@thewilkybarkid
Copy link
Contributor Author

Thanks for taking a look @gcanti. Unfortunately, I'm still seeing the same problem.

I'm trying to debug, but if you'd like to reproduce it clone https://github.com/prereview/prereview.org, run npm install fp-ts@rc --legacy-peer-deps then npm test and you should see it.

@thewilkybarkid
Copy link
Contributor Author

Looks like the order of the exports map is important: moving ./* to the end sees it work.

@thewilkybarkid
Copy link
Contributor Author

The same tweak worked on 2.13.0-rc.4 too.

@gcanti
Copy link
Owner

gcanti commented Sep 20, 2022

moving ./* to the end sees it work.

Ahhh interesting, so

"exports": {
    ".": {
      "require": "./lib/index.js",
      "import": "./es6/index.js",
      "types": "./lib/index.d.ts"
    },
    "./HKT": {
      "require": "./lib/HKT.js",
      "import": "./es6/HKT.js",
      "types": "./HKT.d.ts"
    },
    "./es6/HKT": {
      "import": "./es6/HKT.js",
      "types": "./HKT.d.ts"
    },
    "./es6/*": {
      "import": "./es6/*.js",
      "types": "./lib/*.d.ts"
    },
    "./lib/HKT": {
      "require": "./lib/HKT.js",
      "types": "./HKT.d.ts"
    },
    "./lib/*": {
      "require": "./lib/*.js",
      "types": "./lib/*.d.ts"
    },
    "./*": {
      "require": "./lib/*.js",
      "import": "./es6/*.js",
      "types": "./lib/*.d.ts"
    }
}

right?

@thewilkybarkid
Copy link
Contributor Author

thewilkybarkid commented Sep 20, 2022

@gcanti Yep, it must try matching top to bottom.

Edit: confirmed:

Within the "exports" object, key order is significant. During condition matching, earlier entries have higher priority and take precedence over later entries. The general rule is that conditions should be from most specific to least specific in object order.

@gcanti
Copy link
Owner

gcanti commented Sep 20, 2022

2.13.0-rc.6 released, thank you @thewilkybarkid for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment