web-auth-library icon indicating copy to clipboard operation
web-auth-library copied to clipboard

Can't seem to import library

Open anirudhsama opened this issue 1 year ago • 9 comments

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?

anirudhsama avatar Mar 30 '23 13:03 anirudhsama

@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?

koistya avatar Apr 01 '23 22:04 koistya

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

anirudhsama avatar Apr 02 '23 16:04 anirudhsama

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

maccman avatar Jun 24 '23 02:06 maccman

Still running into this. package export is broken.

maccman avatar Aug 18 '23 18:08 maccman

I have the same problem

rossanodr avatar Sep 20 '23 19:09 rossanodr

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

robert-nash avatar Sep 27 '23 14:09 robert-nash

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"
  },

fabhed avatar Dec 02 '23 16:12 fabhed

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?

volod-vana avatar Jan 04 '24 01:01 volod-vana

Likewise, still having this issue with types being missing.

Manouchehri avatar Feb 03 '24 18:02 Manouchehri