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

bug: crypto is not defined #784

Open
2 of 4 tasks
TheMikeyRoss opened this issue Aug 10, 2024 · 14 comments
Open
2 of 4 tasks

bug: crypto is not defined #784

TheMikeyRoss opened this issue Aug 10, 2024 · 14 comments

Comments

@TheMikeyRoss
Copy link

Describe the bug

I followed the express.js tutorial and when I try to make a call to /logto/sign-in I get the following error

[1] const generateRandomString = (length = 64) => jsBase64.fromUint8Array(crypto.getRandomValues(new Uint8Array(length)), true);
[1]                                                                       ^
[1]
[1] ReferenceError: crypto is not defined

How to reproduce?

  1. Create a express backend
  2. Follow the express.js tutorial
  3. See the same error as above

Context

  • Logto Cloud
  • Self-hosted, Logto version = 1.19.0
    • Container (Docker image)
    • Raw Node.js
@TheMikeyRoss TheMikeyRoss added the bug Something isn't working label Aug 10, 2024
@TheMikeyRoss
Copy link
Author

it's coming specifically from handleAuthRoutes

@wangsijie
Copy link
Contributor

What is your environment, it is normal Node.js or other serverless platforms.

@TheMikeyRoss
Copy link
Author

Logto is hosted in a Ubuntu 24 VPS and I'm trying to send api calls to it from a localhost in my local machine using windows 10. (regular node.js 18.x env)

@wangsijie
Copy link
Contributor

Is this error happend in application or Logto itself?

@TheMikeyRoss
Copy link
Author

in my node application in my localmachine in localhost (express.js)

@wangsijie
Copy link
Contributor

If this error happend in SDK runtime, then could you please check the runtime of you Express.js app and see if "crypto" is available, or you can provide a repo that reproduces this error and I'll take a look.

@TheMikeyRoss
Copy link
Author

Yes I have crypto installed and it's listed in my package.json

@wangsijie
Copy link
Contributor

Usually you don't need to install "crypto" manually.

@TheMikeyRoss
Copy link
Author

honestly it was already installed in my project before I started using logto

@wangsijie
Copy link
Contributor

Please provide a minimal project that can reproduce the issue. This will help me better understand and assist you with your problem, for now, there is no enough context.

@TheMikeyRoss
Copy link
Author

The project im using it it is a huge monorepo with 14 workspaces in it. I will try to put together a minimal reproduction

@alaa-eddine
Copy link

I'm encountering the same issue and it's coming from this file : node_modules@logto\express\node_modules@logto\node\lib\edge\generators.js

and it seems that for @logto/express package is not using the right version of @logto/node

here is what I see in generator.js , it's actually referring to crypto without importing it

image

@vacijj
Copy link

vacijj commented Sep 21, 2024

I got the same issue using Node 18. After upgrading to Node 20 it works.

You have to use at least Node 19 or use the --experimental-global-webcrypto CLI flag.

See https://nodejs.org/api/globals.html#crypto_1

Version Changes
v19.0.0 No longer behind --experimental-global-webcrypto CLI flag.
v17.6.0, v16.15.0 Added in: v17.6.0, v16.15.0

@charIeszhao
Copy link
Member

I got the same issue using Node 18. After upgrading to Node 20 it works.

You have to use at least Node 19 or use the --experimental-global-webcrypto CLI flag.

See https://nodejs.org/api/globals.html#crypto_1

Version Changes
v19.0.0 No longer behind --experimental-global-webcrypto CLI flag.
v17.6.0, v16.15.0 Added in: v17.6.0, v16.15.0

Thanks! We'll soon declare minimum version of node 20 in our JS SDK repo, in order to avoid further confusion.
We recommend upgrading to node 20 when using Logto SDKs.

@charIeszhao charIeszhao removed the bug Something isn't working label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants