kriasoft / web-auth-library

Authentication library for the browser environment using Web Crypto API
https://developer.mozilla.org/docs/Web/API/Web_Crypto_API
MIT License
99 stars 8 forks source link

Can't seem to import library #18

Open anirudhsama opened 1 year ago

anirudhsama commented 1 year ago

Hi,

Im trying to import the library using

import { getAccessToken } from "web-auth-library/google"; but I'm getting any error

./pages/api/tts_edge.ts:2:32
Type error: Cannot find module 'web-auth-library/google' or its corresponding type declarations.

  1 | import { NextRequest } from "next/server";
> 2 | import { getAccessToken } from "web-auth-library/google";
    |                                ^
  3 |
  4 | export const config = {
  5 |   runtime: "experimental-edge",
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

What am I doing wrong?

koistya commented 1 year ago

@anirudhsama this library doesn't contain CJS code, just ESM:

https://github.com/kriasoft/web-auth-library/blob/42a722e4cedc09ea2a86f92fe5aed73b19e5de94/package.json#L60-L70

Maybe your bundler expects it to be CJS?

anirudhsama commented 1 year ago

Oh that might be the case. I'm using it in a Nextjs Edge runtime.

maccman commented 1 year ago

I can only import it like this: import { verifyIdToken } from 'web-auth-library/dist/google'

maccman commented 1 year ago

Still running into this. package export is broken.

rossanodr commented 1 year ago

I have the same problem

robert-nash commented 1 year ago

I have the same problem. @maccman's import helped me get the library working though.

fabhed commented 10 months ago

It might be related to how the exports are defined in package.json?

Top-level types field is missing which might cause issues?

  "exports": {
    ".": "./dist/index.js",
    "./jwt": "./dist/core/jwt.js",
    "./google": {
      "types": "./dist/google/index.d.ts",
      "import": "./dist/google/index.js",
      "default": "./dist/google/index.js"
    },
    "./package.json": "./package.json"
  },
volod-vana commented 9 months ago

Same issue here. Looks like there is a pending PR with a fix & few more issues opened all referencing this problem. Can this be fixed? Do you need help with that?

Manouchehri commented 8 months ago

Likewise, still having this issue with types being missing.