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

UnhandledSchemeError node:crypto #344

Open
1 of 4 tasks
lowryrussell opened this issue Jan 19, 2025 · 6 comments
Open
1 of 4 tasks

UnhandledSchemeError node:crypto #344

lowryrussell opened this issue Jan 19, 2025 · 6 comments
Labels
bug Something isn't working nodejs

Comments

@lowryrussell
Copy link

lowryrussell commented Jan 19, 2025

Bug description

Error deploying to Vercel on latest 4.4.0 release. It appears node:crypto was introduced in 4.4.0 (#329). I have locked my posthog-node version to 4.3.0 in the meantime as a workaround.

web:build: Failed to compile.
web:build: 
web:build: node:crypto
web:build: Module build failed: UnhandledSchemeError: Reading from "node:crypto" is not handled by plugins (Unhandled scheme).
web:build: Webpack supports "data:" and "file:" URIs by default.
web:build: You may need an additional plugin to handle "node:" URIs.
web:build: node:crypto
web:build: ../../node_modules/.pnpm/[email protected]/node_modules/posthog-node/lib/index.esm.js
web:build: ../../packages/plugins/analytics/posthog/src/index.ts
web:build: ../../packages/analytics/src/index.ts
web:build: ./components/analytics-provider.tsx
web:build: ./components/root-providers.tsx
web:build: 
web:build: 
web:build: > Build failed because of webpack errors

How to reproduce

  1. Install latest 4.4.0 posthog-node package
  2. Deploy to Vercel

Related sub-libraries

  • All of them
  • posthog-web
  • posthog-node
  • posthog-react-native

Additional context

Thank you for your bug report – we love squashing them!

@lowryrussell lowryrussell added the bug Something isn't working label Jan 19, 2025
@rafaeelaudibert
Copy link
Member

Some extra content: Vercel Edge functions don't seem to support node:crypto, but normal functions do. You could use a normal node runtime as a workaround while we investigate

@juanpujol
Copy link

This broke deployment to Cloudflare Pages too. They don't support node:crypto.

@magnuslundin
Copy link

Same here. Vercel with edge runtime, currently with a locked posthog-node version. Awaiting the investigation.

@CyberClarence
Copy link

CyberClarence commented Feb 2, 2025

same here with cloudflare page and nextjs edge runtime

@CyberClarence
Copy link

CyberClarence commented Feb 2, 2025

i made it work by downgrading to a 1 month old version of posthog-node

bun i [email protected] should do the job

@jokull
Copy link

jokull commented Feb 4, 2025

This should work with Node 17+ and edge runtimes like cloudflare, vercel edge and bun. The library targets node 15+ but security support for that ended almost 4 years ago.

async function _hash(key: string, distinctId: string, salt: string = ''): Promise<number> {
  const data = new TextEncoder().encode(`${key}.${distinctId}${salt}`)
  const hashBuffer = await crypto.subtle.digest('SHA-1', data)
  const hashArray = Array.from(new Uint8Array(hashBuffer))
  const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('')
  return parseInt(hashHex.slice(0, 15), 16) / LONG_SCALE
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working nodejs
Projects
None yet
Development

No branches or pull requests

7 participants