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

Cannot seem to import jwtVerify from a TypeScript file and run jest tests against it #145

Closed
2 tasks done
nulltoken opened this issue Jan 14, 2021 · 3 comments
Closed
2 tasks done
Labels
duplicate This issue or pull request already exists

Comments

@nulltoken
Copy link

Describe the bug

When importing jwtVerify from a .ts file and trying to leverage exported function from jest .ts tests, we're getting import related errors

$ jest
FAIL src/__tests__/a.ts
  ● Test suite failed to run

    Cannot find module 'jose/jwt/verify' from 'src/a.ts'

    Require stack:
      src/a.ts
      src/__tests__/a.ts

    > 1 | import jwtVerify, { JWTVerifyGetKey } from 'jose/jwt/verify';
        | ^
      2 | 
      3 | const keyRetriever: JWTVerifyGetKey = (_header, _token) => {
      4 |   return Promise.resolve(new Uint8Array(2));

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:306:11)
      at Object.<anonymous> (src/a.ts:1:1)

To Reproduce

A complete end to end repro case is available at https://github.com/nulltoken/jose-import-repro-case

clone, then run yarn.

  • building works fine (ie. yarn build doesn't report any error)
  • running tests fails with the above error

In order to help studying the repro case, a GitHub action has been created => https://github.com/nulltoken/jose-import-repro-case/blob/main/.github/workflows/main.yml
Results of latest run can be audited at https://github.com/nulltoken/jose-import-repro-case/runs/1702720189?check_suite_focus=true

Expected behaviour

Full disclosure: I may not be properly importing the lib (the README doesn't explicitly describe the recommended way to import from TypeScript)

If jose 3.5.1 is supposed to work in the described usage, an update in the README would be great.
If this is a bug, well... I'd really enjoy being able to use this lib and run jest based TypeScript tests against functions leveraging it.

Environment:

  • jose version: 3.5.1
  • affected runtime is: Node.js 14.15.0,
  • other relevant library versions: available in the package.json in the linked repro repository

Additional context
Add any other context about the problem here.

  • the bug is happening on latest jose too.
  • i have searched the issues tracker on github for similar issues and couldn't find anything related.
@panva
Copy link
Owner

panva commented Jan 14, 2021

jest's loader/resolver does not support subpath exports yet, workarounds in #105 #110

@panva panva closed this as completed Jan 14, 2021
@panva panva added duplicate This issue or pull request already exists and removed triage labels Jan 14, 2021
@panva
Copy link
Owner

panva commented Jan 14, 2021

I may not be properly importing the lib (the README doesn't explicitly describe the recommended way to import from TypeScript)

Every single module's documentation shows HOW to properly import.

@nulltoken
Copy link
Author

@panva Thanks a lot for the feedback. The workaround in the jest configuration moduleNameMapper helped and fixed my issue. Maybe this "workaround" may deserve a brief explanation in the README.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants