Skip to content

Reading from "node:crypto" is not handled by plugins #225

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

Closed
vishalvibes opened this issue Mar 18, 2024 · 16 comments
Closed

Reading from "node:crypto" is not handled by plugins #225

vishalvibes opened this issue Mar 18, 2024 · 16 comments

Comments

@vishalvibes
Copy link

Environment:

Node Version: 20.11.1
macOS: 14.2.1
next: 14.1.3
replicate: 0.28.1

I am getting Module build failed: UnhandledSchemeError: Reading from "node:crypto" is not handled by plugins (Unhandled scheme). while building my project.

pnpm build command is causing the issue but pnpm dev (developer mode) works fine.

Screenshot 2024-03-18 at 12 30 44 PM
@aron
Copy link
Contributor

aron commented Mar 18, 2024

Googling your error message, this looks like a known issue with webpack.

webpack/webpack#14798

the fix appears to be telling webpack about this using externals.

module.exports = {
   externals: {
       'node:crypto': 'commonjs crypto'
   }
}

@bigOK666
Copy link

bigOK666 commented Apr 3, 2024

Any updates? I tried the external approach but the problem is not solved. I also tried the config mentioned in https://developer.tbd.website/docs/web5/troubleshooting/common-errors/ . It didn't work either.

My env:
Nextjs: 14.1.4
node: 20.5.0
replicate: 0.29.1

@bigOK666
Copy link

bigOK666 commented Apr 3, 2024

I guess the replicate package is not for interacting with Replicate API in browser. So I need to use HTTP API.

https://www.npmjs.com/package/replicate

@lucasishuman
Copy link

lucasishuman commented Apr 4, 2024

Edited to correct Replicate package version

FWIW ~ I'm seeing the same error.

I am using Turborepo for a few web apps, all Next.js projects.

I am using this Replicate client + the Vercel AI SDK.

It was working OK until v0.2.7 v0.27.0 when I started seeing the 'node:crypto' plugin error when trying to build my project. (same for all subsequent versions of replicate)

I tried some workarounds but haven't solved it yet...

(also, I'm using Yarn for dependency management but doubt that makes a difference)

@bigOK666
Copy link

bigOK666 commented Apr 4, 2024

@lucasishuman which package is v0.2.7? I am considering downgrade Replicate client.

@lucasishuman
Copy link

@lucasishuman which package is v0.2.7?

Sorry, I mistyped the Replicate version...

Replicate v0.26.0 currently runs and builds fine for me so am I am using that for now.

Replicate v0.27.0+ will not build and shows the UnhandledSchemeError: Reading from "node:crypto" ... error.

@himself65
Copy link

Related: #210

@leonardofaria
Copy link

Using Next 14.4.2 and PNPM here. Solved here by editing the next.config.js and tweaking the webpack config:

  webpack: (config) => {
    config.externals.push({
      'node:crypto': 'commonjs crypto',
    });
    return config;
  },

@lucasishuman
Copy link

@leonardofaria - that worked for me, thanks.

@lucasishuman
Copy link

Although... this did not work once deployed to my production environment (on Vercel)

Error: The Edge Function "src/middleware" is referencing unsupported modules:
	- __vc__ns__/1/index.js: crypto

So back to v0.26.0 for now...

@himself65
Copy link

Although... this did not work once deployed to my production environment (on Vercel)

Error: The Edge Function "src/middleware" is referencing unsupported modules:
	- __vc__ns__/1/index.js: crypto

So back to v0.26.0 for now...

What's the nodejs version you are setting? I should be 18, or better 20

@lucasishuman
Copy link

Node 18.18.2 locally - Replicate 0.29.1 + webpack externals config = ok

Node 18.x on Vercel (vercel screen grab below) - Replicate 0.29.1 + webpack externals config = error on build

image

@himself65
Copy link

I just removed the require('node:crypto') code (PR: #243) and built a custom package, and pasted it into my codespace, and it seems to work

Here you can see how I made it: https://github.com/run-llama/LlamaIndexTS/pull/731/files#diff-0a946a42f586de9c04be9cfe31eec6a8ff9d14721b79565958dd13458ab9260e

@mattt
Copy link
Contributor

mattt commented May 2, 2024

Hey everyone. We just released v0.29.3, which includes changes from #250 that should resolve things. Please let us know if they don't. Thanks for your patience and help finding a solution 🙇

@mattt mattt closed this as completed May 2, 2024
@lucasishuman
Copy link

Looks good locally as well as deployed on Vercel using Node 18.x - thanks a ton!

@darshankalburgi
Copy link

Using Next 14.4.2 and PNPM here. Solved here by editing the next.config.js and tweaking the webpack config:

  webpack: (config) => {
    config.externals.push({
      'node:crypto': 'commonjs crypto',
    });
    return config;
  },

Atleast it worked for now

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

Successfully merging a pull request may close this issue.

8 participants