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

Can't seem to import library #18

Open
anirudhsama opened this issue Mar 30, 2023 · 9 comments
Open

Can't seem to import library #18

anirudhsama opened this issue Mar 30, 2023 · 9 comments

Comments

@anirudhsama
Copy link

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
Copy link
Member

koistya commented Apr 1, 2023

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

"type": "module",
"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"
},

Maybe your bundler expects it to be CJS?

@anirudhsama
Copy link
Author

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

@maccman
Copy link

maccman commented Jun 24, 2023

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

@maccman
Copy link

maccman commented Aug 18, 2023

Still running into this. package export is broken.

@rossanodr
Copy link

I have the same problem

@robert-nash
Copy link

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

@fabhed
Copy link

fabhed commented Dec 2, 2023

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
Copy link

volod-vana commented Jan 4, 2024

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
Copy link

Likewise, still having this issue with types being missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants